KatInterview

Real-Time Ranking System for Competitive Programming Platform

System DesignModel answer
MediumModel answerSystem Designleaderboardredissharding

Last updated

Design a leaderboard that tracks millions of users' scores and serves rankings with sub-100ms latency at 50K writes/sec.

Real-Time Ranking System for Competitive Programming Platform

You're building a ranking system for a competitive programming website with millions of active participants. Users accumulate points by completing challenges, and the platform displays their position relative to all other competitors worldwide.

What the System Must Support

Core Operations:

  1. Record score changes: When a user completes a challenge, their total points increase
  2. Fetch top performers: Show the 100 highest-ranked users
  3. Look up individual rank: Given a user ID, return their current position
  4. Show nearby competitors: For any user, display the 50 people ranked immediately above and below them

Scale and Performance Targets

  • User base: 10 million people online at once; 100 million total with scores
  • Write throughput: 50,000 score updates arriving every second during peak hours
  • Read latency: Ranking queries must complete in under 100 milliseconds
  • Consistency model: Score updates must be durable within seconds; rank calculations can tolerate brief eventual consistency

What to Cover in Your Design

  • Overall architecture: which storage systems and caching strategies you'd use
  • Schema and data structures for both persistent storage and the ranking layer
  • How you'd prevent "hot spot" issues when many highly-ranked users update simultaneously
  • Strategies to validate submissions without slowing down the ingestion pipeline

Assume the platform's judge service verifies solutions server-side before sending score updates, so clients never directly report their own points.

Hints

Hint 1

A sorted set data structure with O(log N) rank lookups can fit 100M users in ~10GB of memory

Hint 2

Batch and coalesce multiple updates for the same user before writing to the ranking store to reduce load

Hint 3

Precompute and cache the top 100 list separately with a 1-second refresh cycle to serve read traffic from CDN