04QuestionsLeaderboard
04 · Worked prompt
Leaderboard
Design rank updates, top-K queries, tie handling, seasons, and hot-partition control.What a passing answer must show
100 points · 45 minutes
- 20pts
Scope the problem
0–5 minPrioritize the core flows, state the scale, and name the non-goals.
- 15pts
Define contracts
5–10 minIdentify durable entities, APIs, idempotency, and the source of truth.
- 30pts
Complete the diagram
10–25 minTrace one write path and one read path. Label the commit boundary and async work.
- 20pts
Lead one deep dive
25–38 minChoose the highest-risk trade-off and explain the mechanism, alternative, and cost.
- 15pts
Prove reliability
38–45 minWalk a failure, recovery, metric, bottleneck, and evolution path.
One complete box-and-arrow design
Design rank updates, top-K queries, tie handling, seasons, and hot-partition control.

Write
Games + viewers enters through Leaderboard API. Score service owns validation and commits the durable record to Score event store.
Propagate
Season partitions separates the committed write from background work. Rank aggregators can retry safely while it builds Sorted-set index.
Read
Rank coordinator serves from Sorted-set index, then checks authoritative state whenever freshness, policy, or correctness requires it.
Say this first: Score events are durable; partition-local ordered sets feed a versioned global top-K snapshot.
Open the full whiteboard ↗Explain every boundary before adding more boxes.
Score events are durable; partition-local ordered sets feed a versioned global top-K snapshot.
Design rank updates, top-K queries, tie handling, seasons, and hot-partition control.
Millions players · write bursts · low-latency top-K · deterministic ties. State average and peak load, stored bytes, bandwidth or open connections, and the growth horizon before choosing a partitioning strategy.
End-to-end walkthrough
Trace the architecture in this order.
- 01
Enter and classify the request
Games + viewers → Leaderboard APIScore events + rank reads enters over HTTPS / RPC. Leaderboard API handles identity, admission, routing, and request context; it deliberately does not own domain truth.
- 02
Validate, then cross the commit boundary
Leaderboard API → Score service → Score event storeScore service receives the command, checks invariants and retry identity, then uses append + CAS to update Score event store. The user-visible mutation is accepted only after this boundary succeeds.
- 03
Move replayable work off the request path
Score service → Season partitions → Rank aggregators → Sorted-set indexScore service emits publish after commit; Rank aggregators uses consume and update rank to build Sorted-set index. Consumers must tolerate duplicate delivery and stale retries because this path is asynchronous.
- 04
Serve reads from the right authority
Leaderboard API → Rank coordinator → Sorted-set index / Score event storeRank coordinator uses ordered seek for the common, read-optimized path and strong read when correctness or repair requires authoritative state. The API must state the freshness promise instead of hiding it.
- 05
Deliver without changing the source of truth
Rank aggregators → Rank cache → Games + viewersRank aggregators uses fan-out; Rank cache returns updates over stream / push. Sequence IDs, reconnect cursors, and backpressure make delivery resumable without turning a socket into durable state.
Ownership ledger
Why each box exists—and what it must defend.
| Component | Owns | Why it exists | Interviewer probe |
|---|---|---|---|
| Leaderboard APIAuth + season routing | Identity, admission, routing | Protects the system edge and attaches trusted context before domain work begins. | Timeout budgets, quotas, regional routing |
| Score serviceDedupe + conditional update | Write invariants and retry identity | Serializes or conditionally applies state changes before acknowledging success. | Concurrent writes, deduplication, hot ownership |
| Score event storeAuditable score changes | Authoritative durable state | Provides the one record used to resolve disputes, recover, and rebuild projections. | Partition key, replication, consistency |
| Season partitionsPlayer-keyed updates | Durable asynchronous handoff | Absorbs bursts and lets slow or optional work retry independently of the request. | Ordering key, lag, retention, dead letters |
| Rank aggregatorsLocal heaps + global merge | Replayable processing | Runs expensive, fan-out, or side-effecting work with leases and bounded retries. | Idempotency, poison work, autoscaling |
| Sorted-set indexPublished rank snapshot | Rebuildable query state | Shapes data for the dominant reads without weakening the write-side invariant. | Freshness, versioning, rebuild time |
| Rank coordinatorTop-K + around-me | Read composition and freshness policy | Chooses authoritative or derived state and returns a stable client contract. | Fan-out, cache policy, partial results |
| Rank cacheHot top-K by season | Connection and delivery state | Separates open connections and fan-out pressure from durable domain state. | Reconnect, ordering, slow consumers |
Physical design
Name the database, shard key, indexes, and guarantees.
- Database + storage
- Redis sorted sets serve live rank windows; Cassandra/Scylla or SQL stores durable score events/totals; object storage keeps snapshots.
- Partitioning / sharding
- Partition by board_id + hash(player_id); compute local shard top-K and merge into regional/global boards.
- Indexes
- Unique event_id, durable (board_id, season, player_id), sorted-set score order, and player history by time.
- Replication + consistency
- Score acceptance is durable/idempotent. Served rank is a versioned, freshness-bounded projection reconciled from score events.
- Cache, queue + recovery
- Stream score events to aggregators; cache top ranges and player-neighbor windows, never the only score copy.
- Capacity math
- Estimate updates/sec, reads/sec, players/board, top-K, hot tournaments, and rank freshness.
- Alternative rejected
- One global Redis ZSET is ideal initially but becomes a single CPU/memory owner; hierarchical top-K removes that ceiling.
Deep-dive candidates
Pick one risk and explain the mechanism, alternative, and cost.
Partitioning
Hash players for write balance and maintain bounded top candidates per shard
Partitioning by score creates moving hot rangesAround-me rank
Use sorted-set rank operations or approximate count summaries plus local seek
Top-K and arbitrary rank are different query shapesCorrections
Append compensating score events and rebuild affected indexes from the log
Silent overwrites destroy auditabilityFailure pressure test
Show detection, containment, recovery, and evidence.
Duplicate event
Deduplicate source event ID inside score update transaction
duplicate score attemptsHot player
Serialize by player ID and rate-limit abusive sources
conflicts per playerSeason rollover
Freeze old writes, create new namespace, and publish pointers atomically
cross-season writes- Functional requirements and non-goals
- Peak traffic, storage, bandwidth, and growth
- Entities, APIs, idempotency, and pagination
- Source of truth and consistency promise
- Partition key, replicas, caches, and hot spots
- Retries, backpressure, failover, and reconciliation
- Latency, saturation, correctness, and recovery metrics
- Security, migration, cost, and multi-region evolution
A four-part talk track
- Scope
“I’ll prioritize update player scores at high write rates and read top-k, around-me, and friend ranks.”
- Scale
“The design changes around millions players · write bursts · low-latency top-k · deterministic ties.”
- Decision
“Exact global order is costly; partial candidates enable fast approximate top-K.”
- Risk
“The first failure I want to pressure-test is: Hot players, ties, replay, and season rollover can corrupt rank stability.”
Reference details
Open these only after you can explain the diagram above without reading.
01Requirements and state lifecycle4 requirements
- Update player scores at high write rates
- Read top-K, around-me, and friend ranks
- Handle ties and seasonal resets deterministically
- Support audit and anti-cheat correction
Each transition must be durable, observable, and safe to retry.
02Data model and APIs4 entities · 3 interfaces
Core entities
event_id, player_id, season_id, delta, reasonOwner: Score logplayer_id, season_id, score, versionOwner: Rank servicepartition, score, tie_key, player_idOwner: Sorted indexseason_id, rules, start, end, stateOwner: Season serviceExternal interfaces
/v1/scores/eventsApply one signed idempotent score event
/v1/leaderboards/{season}?limit=100Read a published top-K snapshot
/v1/leaderboards/{season}/players/{id}Read score, rank, and neighbors
03Deep dives and trade-offsChoose one
Partitioning
Hash players for write balance and maintain bounded top candidates per shard
Partitioning by score creates moving hot rangesAround-me rank
Use sorted-set rank operations or approximate count summaries plus local seek
Top-K and arbitrary rank are different query shapesCorrections
Append compensating score events and rebuild affected indexes from the log
Silent overwrites destroy auditability04Failures, recovery, and evidence3 scenarios
Duplicate event
Deduplicate source event ID inside score update transaction
duplicate score attemptsHot player
Serialize by player ID and rate-limit abusive sources
conflicts per playerSeason rollover
Freeze old writes, create new namespace, and publish pointers atomically
cross-season writes05What makes the answer seniorInterviewer signals
- Ask whether rank must be exact before choosing the index
- Tie-breaking must be part of the key, not UI logic
- Use an event log when corrections and anti-cheat audit matter
- Primary trade-off: Exact global order is costly; partial candidates enable fast approximate top-K.
Can you redraw it from memory?
- Name the source of truth.
- Trace the write and read paths.
- Defend one trade-off.
- Recover from one failure.