System Design AI

Design a Leaderboard: The Junior, Senior and Staff Answer

A leaderboard question probes three things: how you think about scale, how you model mutable ranking data, and how you balance latency against consistency. The interviewer wants to see whether you can turn a vague product brief into a concrete request path, choose the right AWS building blocks, and anticipate failure modes.

What the interviewer is testing

  • Scalability – can you handle millions of players and thousands of score updates per second?
  • Data modeling – how do you store a mutable, ordered list efficiently?
  • Latency vs consistency – when is it okay to show a slightly stale rank?
  • Operational thinking – monitoring, cost, and failure recovery.

Requirements and driving numbers

RequirementTypical value (ballpark)
Users (players)~10 million total, active 10 % daily
Write rate (score submissions)~100 k updates per minute ≈ 1.7 k per second
Read rate (top-N fetches)~5 k reads per second for top 100, plus occasional per-user rank lookups
Latency target< 200 ms for reads, < 500 ms for writes
ConsistencyEventual for global view, strong for per-user recent score

These numbers drive the choice of storage and caching layers. The write rate of ~1.7 k /s is modest for DynamoDB, but the read pattern—many hot reads of the same top-N slice—calls for an in-memory cache.

Core design in prose

Request path, one hop at a time

  1. Client submits a new score – HTTP POST to an API Gateway endpoint.
  2. API Lambda validates the payload and forwards the record to an SQS queue (decouples spikes).
  3. Worker Lambda consumes the message and writes the new score to a DynamoDB table keyed by (game_id, user_id). The table has a GSI on score to enable range queries.
  4. After the write, the worker publishes an update event to an MSK Kafka topic.
  5. A separate consumer reads the event and updates a sorted set in ElastiCache (Redis). The sorted set stores score:user_id for fast top-N retrieval.
  6. Read path – a GET request hits API Gateway → Lambda → checks ElastiCache for the requested slice. If missing, Lambda falls back to DynamoDB, writes the result to the cache, and returns the data.
  7. Audit – every write is also appended to an S3 bucket (partitioned by date) for compliance and replay.

Data model

  • DynamoDB table LeaderboardScores
  • Partition key: game_id
  • Sort key: user_id
  • Attributes: score, last_updated
  • GSI: score-index with game_id as partition key, score as sort key, projected attributes score, user_id.
  • Redis sorted set game:{game_id}:rank
  • Member: user_id
  • Score: numeric score
  • Supports ZRANGE for top-N and ZRANK for per-user rank.

Key choice and alternatives

The design picks DynamoDB for its ability to handle high write throughput with low operational overhead. An alternative is Aurora MySQL with a composite primary key and an index on score. Aurora offers strong consistency but requires more tuning for scaling writes, and the read-heavy top-N queries would still need a cache layer. DynamoDB’s on-demand capacity lets us hedge against traffic spikes without pre-provisioning.

What a complete junior answer covers

  • Lists the basic components (API Gateway, Lambda, DynamoDB, Redis).
  • Draws a simple request flow: client → API → Lambda → DynamoDB → cache.
  • Mentions latency target and basic read/write rates.
  • Touches on data model (primary key, score attribute) but may not discuss GSIs.
  • Accepts eventual consistency for the leaderboard.

What a senior answer adds

  • Sharding – partitions the DynamoDB table by game_id and possibly by a hash prefix to spread hot keys.
  • Cache warming – a background job keeps the top-N slice hot in Redis.
  • Write-through vs write-behind – explains why the SQS decoupling is useful for bursty traffic.
  • Consistency trade-off – uses DynamoDB’s ConditionExpression to prevent score regression, and explains when stale ranks are acceptable.
  • Metrics – CloudWatch dashboards for write latency, cache hit ratio, and queue depth.

What a staff answer adds

  • Failure modes – describes how to handle cache miss storms (thundering herd) with exponential backoff and a fallback to DynamoDB, and how to recover from a Redis node loss using cluster replication.
  • Operational concerns – discusses TTL on cache entries, DynamoDB autoscaling policies, and S3 lifecycle rules for audit logs.
  • Cost analysis – rough estimate: DynamoDB on-demand writes for 100 k/min are about 144 million a day, on the order of $100 / day at published per-million write prices; Redis (cache-hit > 90 %) costs a few hundred dollars per month; SQS and MSK add modest overhead.
  • Trade-off defense – argues why eventual consistency is acceptable for a global leaderboard but strong consistency is kept for a user’s personal best view.
  • Testing & deployment – blue-green deployment of Lambda versions, canary rollout of schema changes, and chaos testing of the cache layer.

Mistakes that sink this question

MistakeWhy it hurts
Ignoring read-heavy patternLeads to DynamoDB scans, which explode cost and latency.
Using a relational DB without cacheCannot serve top-N queries at < 200 ms under load.
Over-engineering consistencyAdds latency and complexity for little gain.
Forgetting to handle hot keysA single popular game can throttle the partition key.
No monitoring planInterviewer will ask how you know the system is healthy.

How to practice this

  1. Study the worked leaderboard design in the System Design AI library. It shows the canvas with each component annotated.
  2. Write your own answer on a blank canvas: draw the request path, list the AWS services, and note the numbers you chose.
  3. Use the practice brief rubric to self-review: check that you covered requirements, data model, scaling, and failure modes.

Questions people ask

What is the simplest way to store a mutable ranking list?

Use a DynamoDB table for durable writes and a Redis sorted set for fast top-N reads. The sorted set gives O(log N) inserts and O(log N + M) range queries, where M is the number of members returned.

How do you prevent a user from submitting an older score?

In the write Lambda, include a conditional update that only overwrites if the incoming score is greater than the stored score attribute.

When should you choose Aurora over DynamoDB for a leaderboard?

Choose Aurora if you need strong transactional guarantees across multiple related tables, or if you already have a relational data model and can afford the operational overhead.

What operational metric matters most for the cache layer?

Cache hit ratio. A high hit ratio (> 90 %) means most reads stay in memory, keeping latency low and DynamoDB read cost minimal.