Case 7
Merging Moves and Leaderboards
Concurrent edits to shared boards need versioning; leaderboards need approximate top-K at scale.
Step-by-step walkthrough
Play path — validate and persist
- ① POST /move — Player submits a move; server is authoritative, not the client.
- ② UPDATE WHERE version=N — Optimistic lock on board row; stale version rejected with 409 Conflict.
- ③ Append move event — Immutable move log supports replay, spectators, and audit.
Score path — leaderboard and timers
- ④ ZADD score — Redis sorted set updated on valid move; top-100 is O(log N + 100).
- ⑤ Trigger forfeit — Scheduler fires when turn timer expires; API applies forfeit rule.
- ⑥ GET top-100 — Leaderboard reads from Redis, not a full table scan in Postgres.
Why these technologies?
leaderboardversioningRedisevent sourcingCRDTPostgreSQLQPS