Multiplayer Game Leaderboard 00:00:01 The high score survives even if the ranking cache disappears Asha posts a personal best just before the weekly competition closes. Design an illustrative leaderboard with an authoritative result record and a fast ordered view. They serve different reads and need different recovery guarantees. The game server sends the result with its signature, match, player, mode and time. The intake checks the signature and the limits. Impossible results wait in review. The result is appended to the log. Only now is it accepted. Under this game's best-score policy, retain the larger verified score and the tie-breaking data that belongs to that achievement. ZADD with GT moves the player. About 28 steps among 250 million. Validate and durably identify the match outcome before updating the derived ranking. A repeated result should not inflate a score or reverse a higher verified best. Keep enough evidence to rebuild the ordering after a failure. 00:01:07 Thousands of spectators ask for the same hundred names The public top-hundred page is highly reusable. Asha's personal neighborhood is not. Cache the shared ranking snapshot for a short declared period, then fetch only player details needed for the visible entries. The request names the board and the week. At peak about 98.6% of these looks end here. On a cache miss, read the first hundred entries in the selected descending ranking order. The board holds IDs only. Names come together from the profile cache. The list goes back with ranks, scores and movement. A ten-second cached public page may briefly show the old leader even after a verified result is saved. Specify the acceptable freshness and make the update timestamp visible where the competition requires it. 00:01:58 Asha wants the five competitors on either side The player is far below the top hundred but still wants to see nearby competitors. An ordered index can locate a member and retrieve a short range without asking the service to sort every score for every request. Personal, so it passes the edge without being kept there. The skip list adds up the members each jump passes. ZCARD knows the size at once. The worked range spans eleven positions, with the selected competitor and up to five entries on either side. Names are added, with the distance to the next place. Define whether displayed rank is one-based while the underlying index is zero-based. At either end of the list, clamp the neighborhood so the screen shows available players rather than inventing a missing neighbor. 00:02:44 Equal scores need an explicit rule Max and Asha both reach forty-eight thousand five hundred. The competition says the earlier achievement takes precedence. A storage engine's default ordering of equal values is not automatically that competition rule. Max and Asha both have 48,500. Max reached it earlier. Subtract the achievement's time offset from a fixed limit so an earlier time ranks higher within this bounded example. The high bits are equal, so the low bits decide. Max is ahead. The example encodes a bounded time ordering beneath the score. Check bit ranges and exact numeric precision before packing fields into a sorted-set score. An explicit composite ordering is another implementation of the same published policy. 00:03:28 Rebuild the view while new results keep arriving During the final hour the ranking primary fails. Do new match results have to be lost? Follow the durable intake separately from the temporarily unavailable sorted view. The last writes may be missing on the replica, because replication is asynchronous. The intake and the log do not need Redis. The player sees a pending score. Workers write PostgreSQL and retry the board. Workers replay the last minutes. ZADD with GT makes repeats harmless. A replacement can recover or rebuild the derived ranking and apply subsequent verified results in order. Compare restored results with the authoritative record, including ties. The competition can now explain why Asha has a score, a rank and a particular position among equals.