CMD Guide
HomeSystem DesignData Partitioning

Partitioning Methods

Partitioning means splitting one logical table across many physical stores so that no single machine has to hold — or serve — all of it. There are exactly two axes you can cut along, and every named scheme is a combination of the two:

A single table can be cut both ways at once; that combination is called hybrid partitioning. Keep the two axes straight and the rest of this lesson — including the trade-offs — falls out cleanly.

diagram
diagram

Horizontal partitioning (sharding)

You pick a partition key — say, the user's home region — and route each row to a shard based on that key. A login for a US user touches only the Americas shard; the other shards never wake up for that request. This buys three things: each node holds less data, queries scan less, and writes that used to contend for one machine's CPU, locks, and disk are now spread across N independent machines, which raises the write ceiling.

The whole scheme lives or dies by the key. If the key's values aren't evenly distributed across shards, you get skew: some shards run hot while others idle, and your slowest shard — not your average shard — defines your tail latency and your capacity ceiling. Partitioning users by geography quietly assumes regions are evenly populated. They are not.

Worked example: what skew actually costs you

Take 100M users across 4 region shards, serving 12,000 requests/sec in total. If the load were perfectly even, every shard would hold the mean of 25M rows and serve the mean of 3,000 QPS. Real geography looks more like this:

ShardRegionRowsRows vs meanQPSQPS vs mean
0Americas45M1.8×6,0002.0×
1Europe30M1.2×3,5001.17×
2Asia20M0.8×2,0000.67×
3Oceania5M0.2×5000.17×

Note that the skew is worse on the traffic axis than on the storage axis, because active users cluster even more tightly than raw accounts. Shard 0 (Americas) carries 1.8× the mean on rows but 2.0× on QPS — it is your bottleneck, and you must provision every shard's hardware for it or watch it fall over. Shard 3 (Oceania) sits at one-fifth of the mean on rows and only about one-sixth (0.17×) on QPS — nearly idle capacity you are paying for. The rows-to-QPS mismatch is the whole point: a key that balances storage can still leave traffic lopsided.

So Americas is 2× hot — what do you actually do? Three exits, in escalating cost: (1) split the hot range — Americas becomes Americas-East/Americas-West, two shards each at roughly 1.0× the mean (this works because range boundaries are editable; it is exactly what dynamic partitioning automates — see Rebalancing Strategies); (2) go hybrid — keep geo routing for residency, but consistent-hash user_ids within each region so a region's load spreads over k nodes (see Data Sharding Techniques); (3) re-key entirely to hash(user_id) — perfect balance, but you forfeit region locality and pay a full one-time migration. Choose (1) when the skew is between coarse ranges, (2) when residency law pins the outer key, and (3) only when the locality was never actually used.

diagram
diagram

Choosing the key: range vs. hash

There are two ways to map a key to a shard, and picking between them is the first real judgment call in sharding:

So the trade is balance (hash) vs. locality (range). Reach for range when your dominant query is a scan over ordered keys; reach for hash when your dominant query is a point lookup and even load matters more than ordering. One footgun with plain mod N: changing N reshuffles almost every key. The fix — consistent hashing — is covered in the next lesson, Data Sharding Techniques.

See it: hash vs. consistent hashing on the ring

Hash sharding with plain hash(key) mod N looks fine — until you add or remove a node and almost every key remaps. The debugger below runs 120 keys through modulo, consistent hashing, and consistent hashing + virtual nodes. Step the node crash scenario and predict how many keys move — that number is the interview answer.

Vertical partitioning

Instead of cutting rows, you cut columns: pull the small, hot, frequently-read fields into one store and leave the large, cold, rarely-read ones in another. It pays off when a row mixes both.

Take a user row that is roughly 2 KB — most of that is a bio, JSON settings, denormalized blobs, and preferences that a profile-hover almost never needs. The hot “presence card” a hover does need is just id, name, avatar_url, and last_seen. Budget it honestly: id 8 B + name ~20 B + avatar_url ~60 B (a URL alone is usually 60–100 B) + last_seen 8 B ≈ ~100 Bnot the ~40 B an over-optimistic estimate might suggest. Splitting the hot card into its own narrow table means a hover reads ~100 B instead of ~2 KB: about 20× less data per lookup.

Read that 20× as a logical row-size ratio, not a literal disk-I/O figure. Real reads are page/block-granular, so the exact I/O saving depends on how many rows share a page and on caching. But because vertical partitioning physically separates the hot columns, a narrow hot table packs many more presence cards per page — so the direction is right and the win is real, just not a clean 20× at the block layer.

diagram
diagram

Hybrid partitioning

Real large systems combine both axes. Shard the users table horizontally by region, then vertically split each shard into a hot presence store and a cold profile store. A US profile-hover is then a point read of ~100 B from a single shard's hot store — small on both axes at once. That compounding is the appeal, but so does the operational cost: you now maintain two split strategies, and a query that needs cold columns for a range of users pays both a cross-shard fan-out and a hot-to-cold join.

The pitfalls any split introduces

Both cuts break the one thing a single table gave you for free — the ability to answer a query from one place:

When to use it — and when not

Reach for horizontal partitioning when a single table's data volume or write throughput genuinely exceeds what one well-indexed node (plus read replicas) can serve. Then pick the key by your dominant access pattern: range for scan-heavy, ordered workloads (accept the hotspot risk); hash for point-lookup workloads where even load matters more (accept the loss of range locality).

Reach for vertical partitioning when a single row mixes a small, hot, frequently-read column group with large, cold, rarely-read columns — the presence-card-vs-blob shape above.

When not to:

Sources

Adapted and expanded from the “Partitioning Methods” lesson in this System Design track, with the worked skew example, honest byte budget, and range-vs-hash / when-not-to trade-off analysis added for depth. For a rigorous treatment of partitioning, skew and hotspots, and rebalancing, see Martin Kleppmann, Designing Data-Intensive Applications (O'Reilly, 2017), Chapter 6, “Partitioning.” Consistent hashing is covered in the next lesson, Data Sharding Techniques.

🤖 Don't fully get this? Learn it with Claude

Stuck on Partitioning Methods? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Partitioning Methods** (System Design) and want to truly understand it. Explain Partitioning Methods from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Partitioning Methods** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Partitioning Methods** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Partitioning Methods** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes