Building the live quiz loop in Statsû
Friends answering the same NPB question at the same moment sounds simple. It is not. This is a log of the loop that actually shipped: a question opens, everyone locks an answer, scores land, and the next question starts before the group loses the thread.
The moment that has to feel instant
Statsû is a baseball quiz you play with friends. The product promise is a shared beat: a question appears, you stab at an answer, and you see who got there first. If that beat drags, it stops being a game and becomes a loading screen with extra steps.
友達と同じ問題を、同じ瞬間に解いている感覚が大事だった。遅延が乗ると、ただの順番待ちになる。
The first version opened a question, waited for every device to check in, then revealed. It fell apart the first time someone was on the Chuo line. One late phone held four other people in a polite stall.
Don’t wait for the last device
The loop now has a hard window. The server broadcasts the question with a close time. Clients can join late and still answer if the window is open. When the window ends, late devices are scored as no-answer — not as a reason to stall the room.
async function closeQuestion(room, qid) {
const q = room.questions.get(qid);
if (!q || q.closed) return;
q.closed = true;
// late joins become spectators
const scores = tally(q.answers, q.correct);
await room.broadcast({
type: "reveal",
qid,
scores,
});
}
“It felt slow only when we waited for me.” — a note from a friend after the train test.
A few rules I am keeping:
- The room clock is the server clock. Clients render a countdown from that.
- A reconnect mid-question gets the remaining window, not a restart.
- Reveals are idempotent. A double-close must not reshuffle scores.
- Spectator mode is better than a frozen lobby.
What I would still change
Ties on a buzzer still feel a little soft. I am not timing to the millisecond, and I do not want to. For a group of friends, “same beat” matters more than a photo finish. The next pass is about the feeling of the countdown, not a faster database.
If you want to try the quiz, Statsû is linked from inasaku.dev. This post is just the part I kept tripping over.
Sample post. Set draft: true in the frontmatter to drop it from the live list, the feed, and its page.