May we use cookies so Meta, Google, LinkedIn and ChatGPT see your visit and we learn which ads work? PrivacyMay we use cookies to see which pages help, and let Meta, Google, LinkedIn and ChatGPT see your visit, so we know which of our ads work? That way we spend less on ads that do not work. We do not sell your data, and the site works the same if you decline. You can change your answer at any time under Cookie settings at the foot of the page. Privacy policy
Loading...
System Design and AI Engineering, by Roni Das. 989 interactive lessons in two courses.: 770 in System Design and 219 in AI Engineering.
Start LearningSystem design interview guide
in this guide
7 parts open to everyone · 3 with a free account · 3 with the course
You can read 7 of 13 parts. A free account opens the deep dive; the course opens all of it.
Interviewers like this problem because it forces you to reason about a data structure and a workload at the same time. A weak answer reaches for a SQL ORDER BY and a LIMIT and stops there. A strong answer recognizes that the hard query is not the top 10, it is the rank of an arbitrary user computed for millions of viewers, and that this is exactly what a sorted set solves in logarithmic time. From there the problem opens into batching write-heavy updates, sharding a structure that does not shard cleanly, deciding when an approximate rank is acceptable, and handling time windows and ties. It tests whether you can separate cheap operations from expensive ones and whether you know when to trade exactness for scale.
This page is the free part.
₹1,111 in India$35 everywhere elseonce, for the whole course
The System Design course covers the Leaderboard design across a run of lessons, not one page. These 4 alone are about 111 minutes of step-by-step reading, every one with a quiz.
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
This guide is built on these 5 lessons. Each one teaches one piece of the Leaderboard design above, step by step.
Lifetime access for ₹1,111 in India or $35 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Two courses by the author of this page:
770 lessons · 18 free to read
₹1,111 in India · $35 elsewhere, once
Get System DesignYou own this course
219 lessons · 10 free to read
₹1,333 in India · $35 elsewhere, once
Get Generative AI and Agentic AIYou own this course
Save your progress and get the interview checklist PDF
A popular mobile game or fitness app can have tens of millions of players whose scores change constantly during an event. Every one of them wants two things on the same screen: the global top 100, and their own rank among millions of others. Doing both in a few milliseconds, while scores are being written thousands of times per second, is the whole problem. A public estimate that circulates in engineering write-ups is that a Redis sorted set with around 100 million members uses on the order of several gigabytes of memory, so a single node can carry a large board but not an unlimited one.
A leaderboard looks trivial until you attach real numbers to it. The core data structure that makes it tractable is the sorted set, a collection kept in score order that supports O(log N) inserts, O(log N) rank lookups, and O(log N + M) range reads. Redis implements this with a skip list for ordering plus a hash table for O(1) score lookup, which is why ZADD, ZREVRANK, and ZREVRANGE all stay fast even with millions of members. The read path splits into two very different queries: the global top-N, which is cheap because it is one bounded range read, and the 'my rank' query for an arbitrary user, which is the expensive one because it must be answered for every viewer. Writes are heavy and bursty during events, so you buffer and batch score updates and use atomic ZINCRBY to avoid read-modify-write races. As the member count grows past what one node can hold, you shard, and sharding a single global ranking is genuinely hard because Redis Cluster does not split one sorted set across nodes. You either shard by score range, or hash members across shards and merge per-shard results, or fall back to approximate ranks for the deep middle of the board. Time-windowed boards (daily, weekly, all-time) are separate keys with TTLs. The design is a study in picking exact ranks where they matter and approximate ranks where they do not.
Where it shows up
Asked at gaming companies, social and fitness apps, ad-tech firms, and large product companies such as Meta, Amazon, and Riot-style game backends. It shows up in nearly every mid-level and senior system design loop because it is compact enough to finish in 45 minutes yet deep enough to separate candidates.
Spec sheetLeaderboard
worked through below, with the maths
The hard parts of this design are taught step by step in the System Design course: Redis Cache, Distributed Cache and Database Sharding.
The same small GET measured 0.3 ms at worst on an idle server and 59.1 ms while one other client ran KEYS. Reading one field cost 0.934 ms as a blob and 0.040 ms as a hash.
How a distributed cache spreads keys across nodes with consistent hashing and virtual nodes. Measured tests show why a hot key still overloads a node.
Splitting a database across multiple servers, the nuclear option for scaling writes, and the architecture behind Instagram, Uber, and YouTube.
Using hash functions to distribute rows evenly across partitions, the antidote to hotspots and skewed data.
all part of
System Design Masterclass
770 lessons · about 290 hours · 18 free to read
₹1,111in India, by UPI
$35everywhere else, by card or PayPal
You own this course
Continue with Redis Cachepay once,
yours for life
Live from the course bench
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Active players per board
10M to 50M (estimate)
A large game or app during a live event. Not a published figure for any one company, treated as a design target.
Score updates during an event
~30,000 writes/sec (Derived estimate)
10M active players each producing one score change every ~5 minutes during an event is 10,000,000 / 300 = ~33,000 writes/sec sustained, with higher bursts.
Rank read cost per query
~27 comparisons
ZREVRANK is O(log N). For N = 100M members, log2(100,000,000) is about 26.6, so each rank lookup touches on the order of 27 skip-list nodes. Derived from the O(log N) bound stated in the Redis docs.
Memory for a large sorted set
~a few GB for ~100M members (estimate)
Widely cited community estimate of roughly 6GB for 100M members; exact usage depends on member key length and Redis version, so treat as an order-of-magnitude figure, not a guarantee.
Top-N read cost
O(log N + M), M small
ZREVRANGE 0 99 returns the top 100, so M = 100 regardless of board size. The cost is dominated by the fixed log N seek, which is why top-N is cheap and cacheable.
Peak read fan-out
Reads >> writes
Every player viewing the board issues at least a my-rank plus a top-N read. With millions of concurrent viewers this dwarfs the write rate, so the my-rank path is the one to optimize and cache.
A score event arrives at an API service, usually after the game or app server has validated it so a client cannot post an arbitrary score. The write path does not hit Redis on every single event during a burst; instead updates are buffered and coalesced, either in an in-process batch or through a message queue such as Kafka, so that many small increments for the same player collapse into fewer ZINCRBY or ZADD calls. The score store is a Redis sorted set keyed per board, for example board:global:alltime and board:global:daily:2026-07-10, where the member is the player id and the score is the ranking value. Reads come in two shapes. The top-N read is a single ZREVRANGE 0 N-1 WITHSCORES that is cheap and can be cached at the edge for a second or two because the top of the board changes slowly. The my-rank read is a ZREVRANK for the viewing player plus, optionally, a ZREVRANGE around that rank to show neighbors; this is the query issued by every viewer, so it is the one you protect with caching and, at large scale, with sharding or approximation. A durable copy of scores lives in a primary database or event log so the sorted set can be rebuilt after a restart, since Redis is treated as a fast index rather than the source of truth. When one node can no longer hold the board, a routing layer maps each board or each shard of a board to a Redis node, and the application merges per-shard results for global queries.
In a real interview, sketch this on the whiteboard before diving into any single box.
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
Receives score events from game or app servers, authenticates them, and rejects impossible values so the board cannot be gamed by a malicious client. It is the only writer to the sorted sets, which keeps update logic in one place.
Coalesces bursty updates before they reach Redis, using an in-memory batch or a queue like Kafka. This smooths write-heavy event spikes and lets many increments for one player collapse into a single atomic ZINCRBY, cutting Redis operations sharply.
The ranking index. Each board is a sorted set where the member is the player id and the score is the ranking value. It answers ZADD writes, ZREVRANK rank lookups, and ZREVRANGE top-N and neighbor reads, all in logarithmic time.
A primary database or append-only event log that holds the authoritative score history. Redis is a derived index, so if a node is lost the sorted set is rebuilt from this store rather than trusted as the record of truth.
Maps boards and board shards to Redis nodes and, for a global board split across shards, gathers each shard's top-K and merges them in the application. It also decides when a query can be answered from one shard versus fanned out to all.
Caches the slowly changing top-N and, where acceptable, short-lived my-rank results. This absorbs the read fan-out from millions of viewers so the sorted set is not asked to recompute the same top-100 thousands of times per second.
Creates daily and weekly keys, sets TTLs on them, and rolls windows over at boundaries. It archives finished windows to the durable store and keeps the all-time board separate so a daily reset never erases lifetime totals.
sorted set: board:{scope}:{window}. The core structure. One sorted set per board and window. Redis stores it as a skip list plus a hash table, giving O(log N) writes and rank queries and O(1) score lookups.
Every table for Leaderboard, its keys, and which store fits it and why.
Why a sorted set and how Redis implements it. A sorted set keeps members ordered by a floating-point score and lets you both look a member up by key and walk the set in rank order. Redis implements it with two…
7 deep dives on the parts that break at scale: Why a sorted set and how Redis implements it; The two read paths: top-N versus my-rank; Write-heavy score updates and batching.
Redis sorted set versus SQL ORDER BY with LIMIT. A relational query can produce a top-N with an index, but computing an arbitrary user's exact rank means counting rows above them, which is expensive for every viewer…
6 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
A cheater posts an impossible score. How do you prevent it, and how do you clean up if one gets through?
4 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design Leaderboard with the AI tutor.
Redis publishes sorted sets as its recommended structure for leaderboards and documents the exact complexity of the operations you rely on: ZADD and ZREVRANK are O(log N), ZRANGE and ZREVRANGE are O(log N + M), and ZSCORE is O(1), all backed by a skip list plus hash table. Redis's own tutorials show the concrete command set, ZADD or ZINCRBY to write, ZREVRANGE for top-N, and ZREVRANK for a player's position, and AWS documents the same pattern on ElastiCache for gaming leaderboards. The harder parts, sharding a single global ranking and approximating deep ranks, are less standardized, so the sharding-by-hash-and-merge and bucketed-approximation approaches described here are drawn from general system design practice and community engineering write-ups rather than a single company's published internals. Memory figures such as the often-cited few gigabytes for around 100 million members are community estimates and depend on member key length and Redis version.
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
interview readiness
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
NEWSystem Design Hands-On
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.
Free PDF · 79 pages
25 real tech interview questions, answered in full
Five from each of our AI, GenAI, Inference, Maths for ML and Forward Deployed packs. Each with a diagram and a model answer. Free by email.
free tool
Check these numbers yourself
Put in your own guesses for Leaderboard and see requests per second, storage, bandwidth and servers, with every sum written out.
Open the Capacity EstimatorIt is really nice and good Please join the course