Home/Labs/4 Sharding Strategies Racer
All 280 Labs
INTERACTIVE LAB🗂️

Sharding Strategies Comparison Lab (Interactive)

Flow auto-incrementing orders through Range, Hash, Directory, and Geo sharding to watch skew and scans diverge. Insert sequential orders or a celebrity flash-sale burst and compare write skew, range-scan broadcast cost, and VIP migration flexibility.

Range vs Hash vs Directory vs Geo Sharding

Auto-incrementing orders flow through each strategy; measure write skew and range-scan broadcast cost.

Shard 1

0 rows

0.0% of writes

Shard 2

0 rows

0.0% of writes

Shard 3

0 rows

0.0% of writes

Shard 4

0 rows

0.0% of writes

Orders placed

0

Range scan WHERE id BETWEEN recent

4 shards touched

Write skew

max 0% balanced

Murmur/FNV(key) mod N: perfectly uniform writes, but range scans scatter to every shard. Under Range sharding on auto-increment IDs, 100% of fresh writes hit the newest shard while history sits idle; Hash fixes that but converts scans into broadcasts; Directory pays one lookup-hop for surgical VIP isolation; Geo buys data-sovereignty compliance at the price of uneven regional growth.

How It Works Under the Hood

Four partitioning schemes answer the same question differently. Range sharding keeps ordered keys together, making date scans single-shard but hammering the newest shard with all fresh writes. Hash sharding spreads writes uniformly yet scatters every range query. Directory sharding consults a lookup table, allowing surgical migration of one huge tenant onto dedicated hardware. Geolocation sharding pins users to regional servers for latency and GDPR residency at the price of uneven regional growth.

Core Architectural Principles

  • Range on auto-increment IDs sends 100% of new writes to the latest shard while history idles.
  • Hash mod N balances writes but converts range scans into all-shard broadcasts and forces full resharding at N+1.
  • Directory lookup tables isolate celebrity tenants; geo placement satisfies data-sovereignty rules.
Interview Round Script

Contrast the two headline strategies crisply: range gives localized scans with write hotspots; hash gives uniform writes with scattered scans. Then showcase judgment: directory-based routing for B2B SaaS with one monster tenant, geo-sharding when GDPR demands EU-resident data. Mention Vitess and Citus as the middleware that operationalizes these schemes.

Key Trade-Offs

Every strategy buys one property, scan locality, write balance, flexibility, or residency, by spending another.

Related Curriculum Chapter

Sharding Strategies (Range, Hash, Directory, Geolocation)

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs