KatInterview

Real-Time Ranking Service for Competitive Gaming Platforms

System DesignModel answer
HardModel answerSystem Designleaderboardsscalabilityranking

Last updated

Build a backend that handles millions of score updates per second, returns a player's exact position plus surrounding ranks in milliseconds, and supports friend-only views.

Context

You're building the core ranking infrastructure for a competitive gaming platform with a massive global player base. Players compete across thousands of different games, and they expect to see their exact standing instantly after each match. Beyond viewing the top performers, players want to know where they rank and who's directly competing with them—the handful of players just ahead and just behind.

Core Features

Your system must support:

  1. Score Updates: Players submit their best performance for a particular game. Only genuine improvements should propagate through the system.

  2. Rank with Context: When a player queries their standing, return their precise rank along with k players ranked immediately above them and k players immediately below (e.g., if k=5, show ranks 45-55 when the player is rank 50).

  3. Consistent Tie Resolution: When multiple players achieve identical scores, break ties in a predictable way. Earlier achievements rank higher than later ones with the same score. If timestamps also match, use player identifiers as the final discriminator.

  4. Social Filtering: Players can view rankings filtered to only their friend network, showing where they stand among people they know.

Scale Constraints

  • User Base: 100 million daily active players competing across 10,000 different games
  • Write Traffic: System-wide peak of 100,000 score submissions per second; a single viral game might generate 40,000 writes/sec
  • Read Traffic: 250,000 ranking queries per second globally; hot games see 100,000 reads/sec
  • Latency Target: 99th percentile response time under 50 milliseconds for rank queries
  • Consistency Model: Slight delays (1-2 seconds) are acceptable for viewing others' ranks, but a player must never see their own best score decrease

What to Address

Your design should cover:

  1. API contracts for submitting scores and querying ranks
  2. Storage and indexing choices that enable fast rank computation and range retrieval
  3. Tie-breaking implementation that encodes multiple sorting criteria without precision loss
  4. Scaling strategy for games whose traffic exceeds single-node capacity
  5. Friend filtering approach and the trade-offs between precomputing versus computing on demand

Hints

Hint 1

Most score submissions don't improve a player's personal best—filter aggressively before writing to expensive indexes

Hint 2

Redis sorted sets provide O(log N) rank lookup and range queries, but a single instance can't handle 40k writes/sec for one game

Hint 3

Encode score and timestamp into a single numeric value to leverage native sorted set ordering, but watch out for floating-point precision limits

Hint 4

For friend leaderboards, consider which is cheaper: writing every score update to 200+ friend-specific indexes, or reading a few hundred entries on demand