fix(quiz): persist sessions to Redis and restore them on startup #11

Merged
hmajid2301 merged 1 commit from fix/quiz-persist into main 2026-11-30 11:49:48 +00:00
Owner

Quiz rooms only lived in memory, so any restart or deploy deleted live rooms mid-talk: the presenter got a 404 and the deck dropped to "Live quiz off" (2026-11-30 11:28, room 03cf6c9d…, during a banterbus deploy).

Quiz sessions are now written through to Redis after every change, and restored into the store at startup, matching the other games that already recover from Postgres after a restart.

  • Snapshot (internal/quiz/snapshot.go) holds the quiz, players, scores, answers per round, current stage and join token. Keys are quiz:session:<id> and expire with SessionTTL, which is 24h from creation.
  • Written after create, quiz replace, host actions, player join and answer. The write holds the session lock, so writes land in the same order as the changes.
  • Restore skips expired, duplicate and corrupt snapshots. Players start disconnected and are marked connected again when their socket comes back with the same player_id cookie.
  • Redis write failures are logged and do not fail the request: the room still works in memory as before.
  • Tests: round-trip through a restart (host and audience views equal, game continues), and expired, duplicate or corrupt snapshots are skipped.

The answer timer keeps running during the restart, so a question that was open will be closed if the restart takes longer than the 15 seconds left.

Quiz rooms only lived in memory, so any restart or deploy deleted live rooms mid-talk: the presenter got a 404 and the deck dropped to "Live quiz off" (2026-11-30 11:28, room `03cf6c9d…`, during a banterbus deploy). Quiz sessions are now written through to Redis after every change, and restored into the store at startup, matching the other games that already recover from Postgres after a restart. - Snapshot (`internal/quiz/snapshot.go`) holds the quiz, players, scores, answers per round, current stage and join token. Keys are `quiz:session:<id>` and expire with `SessionTTL`, which is 24h from creation. - Written after create, quiz replace, host actions, player join and answer. The write holds the session lock, so writes land in the same order as the changes. - Restore skips expired, duplicate and corrupt snapshots. Players start disconnected and are marked connected again when their socket comes back with the same `player_id` cookie. - Redis write failures are logged and do not fail the request: the room still works in memory as before. - Tests: round-trip through a restart (host and audience views equal, game continues), and expired, duplicate or corrupt snapshots are skipped. The answer timer keeps running during the restart, so a question that was open will be closed if the restart takes longer than the 15 seconds left.
fix(quiz): persist sessions to Redis and restore them on startup
All checks were successful
CI / e2e (pull_request) Successful in 6m3s
CI / ci (pull_request) Successful in 0s
CI / publish (pull_request) Has been skipped
CI / generate (push) Has been skipped
CI / integration (push) Successful in 1m50s
CI / ci (push) Successful in 0s
CI / unit (push) Successful in 1m3s
CI / unit (pull_request) Successful in 1m10s
CI / lint (pull_request) Successful in 1m12s
CI / generate (pull_request) Successful in 1m24s
CI / integration (pull_request) Successful in 1m51s
CI / lint (push) Successful in 1m38s
CI / e2e (push) Successful in 6m3s
CI / publish (push) Successful in 3m7s
4f22cdc594
hmajid2301 deleted branch fix/quiz-persist 2026-11-30 11:49:48 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hmajid2301/banterbus!11
No description provided.