Bugpit

Lessons › From one user to millions

Stop managing shards

A flash sale: 30,000 req/s, and 60% are cart updates. That's 18,000 writes/s. Every cart belongs to one user and is always fetched by its user ID, so you never need a join.

Play this level

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

The lesson

You could shard Postgres again, but look at what that means: dozens of machines to run, patch and rebalance, for data you only ever fetch by one key.

A NoSQL database such as DynamoDB splits data across partitions by itself, using a key you choose. There are no machines to pick. You pay for each read and write instead.

The key is the real decision. One partition takes 1,000 writes per second, however big the table is. Split carts by store and a popular store goes hot. Split them by user ID and traffic spreads out.

The trade is real: no joins and no text search. Questions you didn't plan for become hard, so use NoSQL for simple, high volume data, not as a drop-in for SQL.

What you have to achieve

30,000 requests a second at the busiest hour, 60% of them writes.

What you learn

Look at the bill: machines dropped by thousands of dollars, but reads and writes now cost about $10,000 a month, so the total is close to sharded Postgres. NoSQL rarely wins on price at steady high traffic. You're paying to stop running shards, and giving up joins to do it.

Check yourself

Which key spreads cart writes evenly?

Show the answer

User ID. A popular store would make one partition hot. Every user has their own cart, so user ID spreads the load.

What do you give up with a NoSQL database like DynamoDB?

Show the answer

Joins and questions you didn't plan for. Use it for simple, high volume data fetched by one key, not as a drop-in for SQL.

Try it yourself

More in From one user to millions

← Pick the shard key One event, many readers →