</> MAANG.io
system design · 301

Advanced

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/480 solved 0% complete

Section 8: One Event, Twelve Thousand Flips - Deep Dive: Sharded Evaluation

Executive Summary: A verified price change has to become the exact set of watches it fires: none missed, none fired twice. We align price-changes partitions with database shards, wrap Section 5's crossing band in a paged conditional UPDATE that writes outbox rows in the same transaction, and show why a mid-band crash is harmless. Then come re-arming, the 500K-watcher hot product, the race with an edit, and two pushbacks.

Alignment: Partition N Owns Shard N

Interviewer: "The change detector just emitted B0EXAMPLE4: 39999 → 27800, priceVersion 812. Who handles it?"

You: "Exactly one evaluator, and it never leaves one shard."

Watches, products and the price-changes topic all use the same key, hash(asin) into 64 logical shards (D5). Kafka partition N carries the events for DB shard N's ASINs and has a single consumer in the evaluator group. That buys per-ASIN ordering (one partition is one log), local transactions on one Postgres shard, and small load: Prime Day's 500 change events/s ÷ 64 ≈ 8/s per shard.

Price-changes partitions 0, 37 and 63 each consumed by the matching evaluator, which commits a local transaction to the matching DB shard

The 64 logical shards sit on 8 physical nodes, 8 each. Rebalancing moves a whole logical shard; the hash never changes, so evaluator 37 simply reconnects to wherever shard 37 now lives. Going past 64 is a planned split of partitions and shards together, never a rehash under load.

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.