HQ Trivia needs no introduction. It has had its ups and downs but one cannot deny the fact that when released, it was a completely new type of experience on our mobile devices and it took the market by storm notching 10 million downloads on Android and iOS devices.
How HQ Trivia works?
HQ Trivia has been all about questions and answers. And the question you may be asking yourself right now is how it all looks like under the hood?
There are a lot of moving parts inside the app’s engine, but one that plays the most crucial role is the producer panel that controls all sorts of stuff happening during the game.
It all starts with the creation of the new game, selecting what type of game it should be, and scheduling when should it happen.
The next step is, of course, adding a set of questions for which you can select a category, add possible answers, and then select which one of them is the correct answer. But that’s just the beginning.
Some questions, as you may know, have videos, photos, or audio files attached to them, and this is the place where the producer can add all of those things to the questions.
Then there is also a matter of not all questions being created equal from a reward standpoint.
After some questions, there are checkpoints that allow players to finish the game and get some bonuses or continue if they’re feeling lucky. This is also something that will be set during the process of creating questions.
The producer can also specify how many coins a specific checkpoint offers to the players. He basically designs the whole in-game reward/gamification system as he plunges in more questions for the day ahead.
Another feature that is a part of the process of game creation is adding gift drops. They won’t be appearing in every game, but have to be prepared and attached to specific questions in advance.
The challenges of HQ Trivia mechanics
As you can see there is a lot happening before the game even begins, but what happens when questions start to pop up on your screen. How do they even get there? Are they being sent to devices in advance? Or maybe there’s a way to take a look at them before they are asked?
It’s not that simple. It turns out the only safe haven for trivia questions to queue before they appear on players’ screens is the backend.
HQ knows this very well and that’s why they send each question only when the time is right, which is when the question is being asked. The way it’s being done is through socket connections which keep each player connected to the server for the entire duration of the game.
Sockets vs REST API
Let’s have a quick look at what sockets are and how they differ from REST APIs, which are used by most apps on our phones.
REST APIs are interfaces that allow us to get specific data from the server. It may be weather, recipes, or photos on Instagram, but the way the communication between devices works is the same: the app asks the server for some data, the server then answers by sending the requested data and the connection is closed.
You can read more about REST API in our article on integrating Google Fit with an Android app.
Sockets on the other hand keep the connection between the app and the server alive for as long as it’s needed, and this allows messages to go back and forth with no need to re-establish the connection.
Those messages, like in HQ Trivia’s example, may contain different kinds of data. For instance, when the presenter is ready to ask the new question, the producer simply clicks the “Start question” button which causes the server to send a message containing said question to all of the players, who then see the question appearing on their screens. Such a message doesn't contain the answer to the question, in case you were wondering, which makes this type of connection the safest for HQ Trivia's purpose.
This is how it works in practice:
1. 10 seconds after a question pops up on the screen, all the players are given the answer.
2. The results are being sent in the exact same way as questions, using a socket connection.
3. The producer selects the option to send the question summary which triggers the server to send each participating player a message with data such as:
What was the correct answer?
Was a player correct or not?
How many points the correct answer has awarded the player?
How many players selected particular answers?
How many players are advancing to the next question?
How many were eliminated?
4. In the event of a player being wrong, the message will also contain the info whether the player should be saved by an extra life or a free pass or if he or she was eliminated.
I hope you enjoyed this behind the scenes of how HQ Trivia creates its quizzes. And hopefully, learning about it will help you come up with your idea for the next big thing.
If that’s the case, then we - at intent - will be happy to help you bring the product to life, using our extensive knowledge and experience. Don’t hesitate to contact us.