Skip to main content
← CONCEPTS / SYSTEM-DESIGN
An end-to-end domain learning journey

Sharded Redis ZSET
Distributed Leaderboard.

Scale real-time leaderboards to 100M+ users by sharding Redis ZSETs, merging Top-K via Min-Heap, and indexing score-range histograms.
Start the journey7 sections· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, shard by userId % K for uniform writes and merge Top-K slices in O(K * T log K).

TL;DR30-second simplified summary
▾

A single Redis ZSET cannot absorb 200k writes/sec or 100M entries on one thread. Partitioning across K ZSET shards distributes writes uniformly, while a Top-K Min-Heap scatter-gather and score-range prefix histogram deliver sub-15 ms reads.

Full walkthrough · 7 stages
01
foundation

Stage 1: Capacity & QPS Math.

Why this matters: Establish capacity & qps math for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 1: Capacity & QPS Math as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish capacity & qps math for Sharded Redis ZSET Distributed Leaderboard.

Stage 1: Capacity & QPS Math establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

Lifecycle & Failure Recovery

Stage 1: Capacity & QPS Math

TTL expiredconcurrent missessingleflight lockvalue cachedCache HitCache MissHot-Key StampedeCoalesced Fill
02
foundation

Stage 2: Single-Node Bottleneck.

Why this matters: Establish single-node bottleneck for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 2: Single-Node Bottleneck as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish single-node bottleneck for Sharded Redis ZSET Distributed Leaderboard.

Stage 2: Single-Node Bottleneck establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

Component Topology

Stage 2: Single-Node Bottleneck

App ServersingressSingleflightcomputeRedis L2storagePrimary DBcontrolGET hot_keyL2 lookup1x origin fetch
Engineering Decision Framework
Problem
How to implement Sharded Redis ZSET Distributed Leaderboard without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, shard by userId % K for uniform writes and merge Top-K slices in O(K * T log K).
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Sharded Redis ZSET Distributed Leaderboard experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Stage 3: User-ID Sharded ZSETs.

Why this matters: Establish user-id sharded zsets for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 3: User-ID Sharded ZSETs as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish user-id sharded zsets for Sharded Redis ZSET Distributed Leaderboard.

Stage 3: User-ID Sharded ZSETs establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

Design Trade-Off

Stage 3: User-ID Sharded ZSETs

Before · Fixed TTL + Direct DB
  • Synchronized cache avalanche
  • 1,000 duplicate DB queries
  • Big-key event-loop freeze
After · Jittered TTL + Singleflight
  • 1 origin fetch per expired key
  • Randomized TTL spreads expiry
  • O(1) HashMap + DLL eviction
04
intermediate

Stage 4: Top-K Min-Heap Merge.

Why this matters: Establish top-k min-heap merge for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 4: Top-K Min-Heap Merge as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish top-k min-heap merge for Sharded Redis ZSET Distributed Leaderboard.

Stage 4: Top-K Min-Heap Merge establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

Request & State Flow

Stage 4: Top-K Min-Heap Merge

App WorkerSingleflight / L1Redis L2Origin DB1. GET key (coalesce duplicates)2. Check L2 distributed cache3. Single origin query on miss4. Populate cache with jitteredTTL
05
intermediate

Stage 5: Score-Range Histograms.

Why this matters: Establish score-range histograms for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 5: Score-Range Histograms as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish score-range histograms for Sharded Redis ZSET Distributed Leaderboard.

Stage 5: Score-Range Histograms establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

06
advanced

Stage 6: Caching & Write-Behind.

Why this matters: Establish caching & write-behind for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 6: Caching & Write-Behind as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish caching & write-behind for Sharded Redis ZSET Distributed Leaderboard.

Stage 6: Caching & Write-Behind establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

07
advanced

Stage 7: Failover & Rebalancing.

Why this matters: Establish failover & rebalancing for Sharded Redis ZSET Distributed Leaderboard.

Think of Stage 7: Failover & Rebalancing as the intuition layer for Sharded Redis ZSET Distributed Leaderboard: Establish failover & rebalancing for Sharded Redis ZSET Distributed Leaderboard.

Stage 7: Failover & Rebalancing establishes how Sharded Redis ZSET Distributed Leaderboard behaves under real production load.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How do you compute global Top-100 across K sharded ZSETs (Check 1)?

Recommended Learning Flow