EasyStarter

Gaming Leaderboard

DatabasesCachingAPI Design

Problem Statement

RankUp is building a leaderboard-as-a-service for mobile game developers. Features:

- Submit scores - game clients submit scores via API. A player's leaderboard entry shows their best score.Global leaderboard - fetch the top-100 players sorted by score, with rank, name, and avatar.Player rank - given a player ID, return their current rank and score in O(log N) time.Friends leaderboard - show rankings among a player's friends only.Time-based boards - daily, weekly, and all-time leaderboards that reset on schedule.Multiple games - serve leaderboards for hundreds of different games from one service.

Targeting 500 games with 200,000 total players and 2 million score submissions per day.

What You'll Learn

Design a real-time gaming leaderboard showing top players, rank lookups, and score history. Build this architecture under realistic production constraints, then validate tradeoffs in the design lab simulation.

DatabasesCachingAPI Design

Constraints

Games supported~500
Total players~200,000
Score submissions/day~2,000,000
Leaderboard query latency< 50 ms
Rank lookup latency< 50 ms
Availability target99.9%
ApproachClick to expand

Interview-Ready Approach

1) Clarify Scope and SLOs

  • Problem statement: Design a real-time gaming leaderboard showing top players, rank lookups, and score history.
  • Design for a peak load target around 116 RPS (including burst headroom).
  • Games supported: ~500
  • Total players: ~200,000
  • Score submissions/day: ~2,000,000
  • Leaderboard query latency: < 50 ms
  • Rank lookup latency: < 50 ms

2) Capacity Planning Method

  • Convert traffic and growth constraints into request rate, storage growth, and concurrency budgets.
  • Keep at least 2-3x safety margin per tier (ingress, compute, storage, async workers).
  • Reserve explicit latency budgets per hop so p95 can be defended in review.

3) Architecture Decisions

  • Databases: Define a clear system-of-record and design read/write paths separately before adding optimizations.
  • Caching: Put cache on hot read paths first and pick cache-aside or write-through explicitly.
  • API Design: Standardize API boundaries, idempotency keys, pagination, and error contracts first.

4) Reliability and Failure Strategy

  • Use strong write constraints (transactions or conditional writes) and explicit backup/restore strategy.
  • Bound staleness with TTL + invalidation hooks for critical entities.
  • Apply strict input validation and backward-compatible versioning.

5) Validation Plan

  • Run one peak-load test, one dependency-degradation test, and one failover test.
  • Verify idempotency for all retried writes and async consumers.
  • Track user-facing SLOs first: p95 latency, error rate, and successful throughput.

6) Trade-offs to Call Out in Interviews

  • Databases: SQL gives stronger transactional guarantees; NoSQL often gives better write scaling and flexibility.
  • Caching: Higher hit rate cuts latency/cost, but stale data and invalidation bugs become primary risks.
  • API Design: Rich APIs improve developer speed but can create long-term compatibility burden.

Practical Notes

  • Redis Sorted Sets are purpose-built for leaderboards - ZADD to submit scores, ZRANGE for top-N, ZRANK for player rank, all in O(log N).
  • Separate sorted sets for daily/weekly/all-time. Use a cron job to archive and reset daily/weekly sets.
  • Friends leaderboard: fetch friend scores from the all-time set (ZSCORE for each friend) and sort client-side.

Learn the Concept

Practice Next

Reference SolutionClick to reveal

Why This Solution Works

Request path: The solution keeps ingress, service logic, and stateful dependencies separated so each layer can scale independently.

Reference flow: Web Clients -> API Gateway -> API Service -> Primary SQL DB -> Redis Cache

Design strengths

  • Cache sits on the read path to absorb repeated queries and keep DB pressure stable.

Interview defense

  • This design makes bottlenecks explicit (ingress, core compute, persistence, async workers).
  • It supports progressive scaling without re-architecting the core request path.
  • It keeps correctness-sensitive state changes in durable systems while offloading background work asynchronously.