</> MAANG.io
system design · 201

Intermediate

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

0/124 solved 0% complete

Partitioning (Sharding)

maang.io System Design Series


Partitioning (sharding) splits a dataset too big for one machine across many, so each node owns a slice. The art is picking a partition scheme — hash (even spread, no range scans) vs range (scannable, but hot-spot prone) — and handling rebalancing and skewed "hot" keys without a full reshuffle. It pairs tightly with Consistent Hashing and Replication.

This deep dive comes in three parts:

  • Foundations & Core Concepts — hash vs range partitioning and why hash % N is a trap.
  • Internals — rebalancing strategies, hot keys, secondary-index partitioning, and request routing, with worked numbers.
  • Interview — Staff/Principal Q&A: choosing a partition key and taming skew.

Partitioning (Sharding) — Part 2: Internals & Implementation

maang.io System Design Series


What is this?

Back to our library that split its collection across branches. In Part 1 we chose the rule for deciding which branch owns a book (range vs hash). That's the easy day. The hard days come later: you open a new branch and have to move books to it without closing the library (rebalancing); one celebrity author's books get so many visitors that one branch is overwhelmed (hot keys); a reader wants "every mystery novel," but your branches are organized by author, not genre (secondary indexes); and a reader walks in and needs to know which branch to even go to (request routing).

Every one of those is a real engineering problem with a real, sometimes surprising, right answer — and the wrong answers are the ones that take a system down at 3 a.m. This chapter is the machinery beneath the tidy declaration you wrote in Part 1.

The one-line idea: the scheme decides where a key belongs, but production is about everything around that — moving partitions cheaply when capacity changes, without the naive hash % N reshuffle that moves everything; splitting hot keys the scheme can't balance on its own; and giving every client a fast, correct answer to "which node owns this key right now?"


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.