Katkat

Design coding platform with global leaderboard

MetaSoftware Engineer · Onsite

Last updated

This question tests the ability to design a high-throughput, real-time leaderboard system that balances strong consistency for rankings with the scalability required for a global user base.

System Design: Global Leaderboard for a Coding Platform

Design a global leaderboard system for a coding platform that hosts millions of daily active users. Users earn points for solving coding problems, and their global rank is updated in real-time.

Functional Requirements

  1. POST /submit-score: Record a score update for a user.
  2. GET /leaderboard: Retrieve the top 100 users.
  3. GET /rank/{userId}: Retrieve the current rank of a specific user.
  4. GET /neighbor-rank/{userId}: Retrieve a user's rank along with the 50 users immediately above and below them.

Non-Functional Requirements

  • Scale: 10 million concurrent users, 50,000 score updates per second.
  • Latency: Leaderboard fetches should be sub-100ms.
  • Consistency: Users expect their points to reflect accurately within seconds (eventual consistency for global rank is acceptable, but individual score updates should be durable).

Scope of Response

  • Describe your high-level architecture, including choice of databases and caching layers.
  • Define the data model (schema design).
  • Explain how you would handle the "hot partition" problem if many top-ranked users update their scores simultaneously.
  • Discuss strategies to ensure anti-cheat mechanisms (e.g., verifying submission timestamps) do not bottleneck the ingestion pipeline.

Hints

Hint 1

Consider using an in-memory sorted data structure, like a Redis Sorted Set (ZSET), to store user scores and ranks efficiently.

Hint 2

For high-volume updates, a write-behind pattern using a message queue can decouple the submission ingestion from the leaderboard processing.

Hint 3

Think about how to shard the leaderboard data if the number of users grows beyond the memory capacity of a single machine.

Follow-up questions

  • How would you modify your design to support seasonal leaderboards that reset every month without affecting historical data?
  • If we introduce 'country-based' leaderboards, how does this impact your database partitioning and query complexity?
  • How would you implement an observability strategy to detect spikes in latency or potential rate-limiting issues for the submission endpoint?