Debug Foundry

When one database can't hold it, give each slice its own database.

Turn it, pause it, drag through the steps. Then try a different key pattern.

Not a video. A small simulation of sharding: every key routed to the one shard that owns it.

Drag to turn · scroll or pinch to zoom

Finished state of the sharding simulation: clients on the left, a router in the middle, three database shards on the right each holding colored slices

Database
everything, one place

1/8First step sentence

    0.0s
    Replay the ending with

    What it's for

    Good to know

    The router shown is hash(key) mod 3 — horizontal partitioning: different rows per shard, not different columns (vertical partitioning, not shown) and not copies (replication, the previous chapter). The mapping is deterministic, so every request for a key finds its shard, and uniform, so even keys spread evenly in this toy. Real systems prefer consistent hashing precisely because adding a shard then moves few keys instead of most — that trade is the next chapter. The costs hide at the boundaries: a question without the key asks every shard and merges (scatter-gather — as slow as the slowest shard, plus the merge), transactions that span shards need coordination, and joins stop being local — each has specific mechanisms and costs, none free, none impossible. Even rows are not even load: a hot key defeats the whole split, because one celebrity's rows live in exactly one shard and no number of extra shards helps; the usual answers (split the hot key, cache it) are workarounds, not math. Resharding is a migration, not a config change: keys move between machines while traffic keeps arriving, routing metadata must switch honestly, and with mod-N hashing going from 3 shards to 4 remaps most keys. And every shard still wants its own replicas for reads and failover — sharding and replication compose, they don't replace each other.

    How it works, step by step

      Why the steps go in this order

      Before you rely on it

      This is a toy: three shards, colored keys, a hand-set hash split and a hand-set hot key. Real shard counts, key distributions and hotspots look nothing like the tray — "each shard holds a third" is this toy's arithmetic, not a property of hashing, and sharding guarantees no linear scaling, no lower latency and no extra availability: losing an unreplicated shard loses access to its slice (a third of the rows here) until it's restored. Whether to shard at all comes last in a real design: caches, replicas and a bigger machine come first, and the cited sources describe production systems with their own measured behavior.

      References