How to design a live trivia game (frontend)
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Everyone sees the same question at the same moment
- A timer nobody can cheat
- A player who drops and comes back
- Thousands watching one round
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
A browser client for a live trivia round: up to 100 players join, a question appears on each screen at one moment, a countdown runs for 10 seconds, the server scores the answers and the leaderboard moves. The answer turns on one idea: the server's clock owns the round, and the client's job is to work out how far its own clock is from that clock, draw the reveal and the countdown from the corrected time, and send each answer for the server to judge by when it arrived. Whatever the client times on its own is a convenience for the player, not a verdict.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
How many people play one round, and how long does each question stay open? | The player count sizes the leaderboard and the lobby list; the question length sets how much a few hundred milliseconds of delay matters, and how long a dropped player can be away and still answer. | Up to 100 players a round, and 10 seconds per question. Both figures come from real products of this kind, so design for a full round of 100 rather than a handful of friends. |
How different are the players' connections? | If everyone sat on one office network, showing a question when it arrives would be fine. The spread of delays is what makes the reveal and the timer hard. | Delays from 100 to 500 milliseconds between a player and the server, and a phone can lose signal for a few seconds mid-question. Design for that whole spread; delays in that range are within what internet play sees. |
Does the server already run the round, or is the client expected to decide when questions open and close? | It settles where the authority sits. If the client decides timing, nothing stops a player from stretching it; if the server decides, the client is a view onto the server's round and needs a clock it can trust. | The server owns the round: it opens and closes each question on its own clock and judges each answer. You design the client and the contract it needs from that server. |
Do points depend on how fast someone answers, or on being right in time? | Speed points make the server's timestamp the whole game and raise the stakes on fairness between fast and slow connections. Right-in-time scoring is more forgiving of a few hundred milliseconds. | An answer scores if it is correct and reached the server in time. Treat speed bonuses as an optional add-on, and say how the timestamp would have to tighten if they were added. |
What should happen to a player whose connection drops for a few seconds? | It decides whether the client keeps a way back into the same round, and whether the server must hold a place for an absent player. | They should carry on in the same round with the same score. A reload of the page on the way back is possible, so whatever gets them back in has to survive one. |
Will people watch a round without playing, and how many? | Watchers change the fan-out shape: a popular round can draw far more watchers than players, and they don't need everything a player does. | Yes, thousands for a popular round. Treat it as a follow-up once the player flow works, since watchers change what is sent, not how players answer. |
When does the client learn the correct answer? | If the correct answer travels with the question, anyone who opens the browser's developer tools can read it before answering, whatever else the design does. | At the reveal, after the question closes, and not before. The question payload holds the text and choices and nothing that gives the answer away. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
Every player gets the same time to answer, whatever their connection | The client's own measurement of time is not trusted for anything that scores. The server records when each answer reached it and compares that with the closing time it set, allowing a bounded rather than open-ended grace, so a slow connection loses at most a fraction of a second rather than the question. |
A tap on an answer shows within 200 milliseconds | The button changes state the moment it is pressed, before the server replies: a selected look and a sending state, with the ack filling in whether it counted. The handler for a tap does no network waiting on the main thread, and the countdown redraws stay cheap so they don't block the tap's paint. |
A player can drop for a few seconds and carry on in the same round | A rejoin token saved where a reload keeps it, a reconnecting state the player sees at once, a countdown that keeps running from the corrected clock while the connection is down, and a server call that returns the whole current round state rather than a list of missed messages. |
The client cannot learn the answer early or stretch its own time | Nothing in the question payload marks the right choice; the client learns it from the reveal message after the window has closed. The on-screen countdown is cosmetic: it locks the buttons for the player's comfort, while the server's arrival stamp settles whether a tap made it, so editing the page changes what the player sees and nothing more. |
Core entities
| Entity | What it holds |
|---|---|
Round | One game as the server sees it, mirrored on the client. |
Question | What the players see and answer, with its window on the server's clock. |
Answer | One player's pick for one question, stamped by the server. |
Score | A player's standing after the latest reveal. |
Client game state | What one tab knows right now; the single source each screen draws from. |
The API
| Endpoint | Notes |
|---|---|
| Called once from the lobby. The client keeps |
| A WebSocket or server-sent event stream opened after the join. The question arrives a little before |
| The client sends the pick and the question it was for, and no timing of its own. The server stamps |
| A tiny endpoint for measuring the clock offset. The client notes local time before and after the call, takes half the round trip as the one-way delay, and keeps the sample with the shortest round trip. Called a few times at join and again between questions. |
| After a reconnect or a reload the client asks for the current state and replaces its own, rather than replaying what it missed. |
The high-level design
Step 1 of 4
Join, a live stream, and buttons
Start with the smallest client that plays: the lobby calls join, opens the live stream, and writes each message into one client game state that the question screen draws from. The answer buttons send the pick straight to the server. It works on a single fast network, and it has the first failure built in: a question is drawn when its message lands, so a player with a 500 millisecond delay sees it later than a player with a 100 millisecond delay by the difference between the two.
What breaks first
The deep dives
Everyone sees the same question at the same moment. Two players sit next to each other, one on fast home broadband and one on a weak phone signal, as the next question opens. What sets the moment the question appears on each screen, and how far apart can those two moments be?
A timer nobody can cheat. A player sets their device clock back and edits the page so the countdown stays above zero. What in your design decides whether their answer was in time, and how late can an answer reach the server and still count?
A concept that helps here: Server authority and lag compensation
A concept that helps here: Optimistic updates and rollbackA concept that helps here: Core Web VitalsA player who drops and comes back. A player's phone loses signal for four seconds while a question is open, and the page may reload when the signal returns. What do they see from the drop until they are back in the round, and what happens to the answer they tapped while offline?
Thousands watching one round. A popular round is shared and thousands of people open it just to follow the scores. What strains first, what does a watcher's screen show, and how often does it change?
A concept that helps here: Batching and coalescing updates
A concept that helps here: WebSockets, server-sent events and pollingA concept that helps here: Sorted sets and leaderboardsConcepts this guide uses
- Clocks and ordering
- WebSockets, server-sent events and polling
- Where state lives
- Server authority and lag compensation
- Optimistic updates and rollback
- Core Web Vitals
- Reconnect and resume
- Sync queues and client idempotency
- Heartbeats and presence
- Batching and coalescing updates
- Sorted sets and leaderboards