Bugpit

Lessons › From one user to millions

Split the database

Your app went write-heavy: 20,000 req/s, and 40% are writes. That's 8,000 writes/sec, and the biggest primary handles 4,800.

Play this level

Free, no account needed. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Replicas can't help here: every copy still has to take every write. A bigger machine stops helping once you hit the largest size. This is the wall that sharding exists for.

Sharding splits the data across several primaries, for example by user ID. Each one holds part of the data and takes only that part's writes.

It isn't free. Each shard costs a full database, a query across shards gets slow, and one dead shard still fails its share of users. Shard only when nothing else works.

What you have to achieve

20,000 requests a second at the busiest hour, 40% of them writes.

What you learn

You scaled writes past a single machine. Notice the bill: sharding is often the most expensive line in the design, which is why teams put it off.

Check yourself

Why couldn't read replicas fix this level?

Show the answer

Every replica still has to take every write. Replicas copy every write, so they add read capacity, not write capacity. Writes past one machine need sharding.

What does sharding do?

Show the answer

Splits the data across several primaries, each taking its own part's writes. Each shard holds part of the data, for example by user ID, and takes only that part's writes.

Try it yourself

More in From one user to millions

← Say no to a flood One shard on fire →