AlgoViz

Design a Multiplayer Game Leaderboard

easy 45 min

Keep 250 million players in order while results arrive all the time, and tell any of them their place in milliseconds.

Explain your choices

Answer first. Then compare your reasoning.

11 questions 0 got it 0 to review11 not marked

Decisions

DecisionChoiceBecauseChange if
OrderRedis sorted setPlace in about 28 stepsSmall board: SQL
Owner of scoresPostgreSQLRebuild and auditVery high write rates: a key-value store
Consistency2 to 5 sNobody can tellFinals: freeze first
FriendsLive ZMSCORE up to 500Always fresh, nothing storedHuge lists: compute before
SplitBy boardA rank stays one commandOne board too large: bands
LiveOwn result only2.3M pushes otherwiseA final of ten players

When they push back

They sayAnswer with
"Why keep PostgreSQL?""Redis replication is asynchronous. I want to lose a machine without losing a score."
"Could DynamoDB or Cassandra do it?""They can own scores by key. They do not count a place among others, so I still need an ordered structure."
"25 GB in one key?""It fits. I worry about the copy after a failure, so I test that time and split before it hurts."
"Why not exactly-once?""Best score with GT gives the same result twice. For sums I would store the result ID."
"Can the CDN hold ranks?""One key for each player would almost never be hit twice in ten seconds."