System Design: Leaderboard Service (A) and Real-Time Messenger (B)
A) Leaderboard Service for a Large-Scale Game
Design a service to:
-
Compute a user’s global rank and their rank within their friendship circle.
-
Retrieve the k users immediately before and after a given user, both globally and within the friend circle ("around me").
-
Handle high write rates, pagination windows, anti-cheat, seasonal resets, and multiple game modes.
-
Detail:
-
APIs (read/write, pagination, friend-scope queries).
-
Data models (e.g., sorted sets, secondary indexes) and schema.
-
Sharding/partitioning strategy.
-
Caching strategy.
-
Consistency model and rank computation approach.
-
Friend-graph integration at read time and/or via materialization.
-
Backfill/batch workflows (rebuilds, seasonal archives).
Assume tens of millions of active players per season and high write rates (hundreds of thousands of updates per second) with low-latency reads.
B) Real-Time Messenger Application
Design a system to support:
-
1:1 and group chat with correct per-conversation message ordering.
-
Delivery guarantees: choose among at-least-once, at-most-once, or exactly-once; justify the choice.
-
Online presence, typing indicators, read receipts.
-
Media sharing (images/video), push notifications, end-to-end encryption (E2EE), offline sync, and fanout for large groups.
-
Spam/abuse controls and disaster recovery.
-
Provide an end-to-end architecture, storage choices, protocols, scale estimates, and operational considerations.
Assume hundreds of millions of DAU, multi-region deployment, and peak traffic in the hundreds of thousands of messages per second.