Final challenge: scale a database
After this: Count replicas, predict stale reads, place and move rows, and choose a side during a partition.
This challenge has five steps, and each step is scored on its own. You will count the replicas a shop needs, predict what reads return from a replica that lags behind, work out which users move when a shard is added, pick a shard key that avoids a hot shard, and choose what a bank's copy should do while the network is broken. You can try as many times as you like, and hints work as they do in the lessons.
Step 1 of 5Count the replicas
Count the replicas
A shop gets 12,000 reads and 500 writes per second. Reads go only to replicas, and one replica serves 3,000 reads per second. How many replicas does it need, and how many writes per second does each replica apply?
Predict the reads
A replica lags 300 ms behind. A price changes from 10 to 12 at 0 ms. Reads go to the replica at 100, 200 and 400 ms. What do the three reads return?
Who moves
Users 1 to 6 sit on 2 shards by user id % 2. A third shard is added, so the rule becomes user id % 3. Which users must move?
Pick a shard key
A social app splits its users table over 4 shards. Most of its users live in one country. Which shard key spreads the rows and the load best?
Choose a side
A bank keeps a copy of account balances in a second data centre. The link between the data centres breaks. A customer asks the second data centre for their balance before a large payment. What should it do, and what does that cost?
- Count replicas and the writes each applies, predict reads from a lagging replica, find the users that move to a new shard, pick a shard key that avoids a hot shard, and choose a side during a partition.