Bank transfers: money never vanishes
A bank app with customers around the world: 6,000 req/s, and 30% move money. A balance must never be out of date, a whole region may go dark, and last week someone ran a delete on the wrong table.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Money is the one place where "usually right" isn't good enough. A replica a second behind can show money that's already gone. So replicas must wait for each write to arrive before it counts. That's "Wait for replicas": slower writes, but every read is current.
Three database machines, not two. With two, a network split leaves each half thinking it's the primary, and both take writes. With three, only the side with two can win.
Copies don't protect you from mistakes. A delete reaches every replica in seconds. Only a backup lets you go back to the minute before it happened.
And a region can fail as a whole. Run the app in a second region with a replica there, ready to take over.
What you have to achieve
6,000 requests a second at the busiest hour, 30% of them writes.
- No broken or illegal connections
- Every read sees the latest write
- The database machines can always agree on one primary
- A mistaken delete can be undone
- After the home region goes dark and a replica takes over, under 1% of requests fail
- No component is overloaded
- Fewer than 0.1% of requests fail
- p99 response time under 500 ms
What you learn
Every protection here made something slower or more expensive: synchronous writes, an extra machine, backups and a whole second region. For money that's the right trade. For likes and views it would be a waste. Choose per kind of data, not per company.
Check yourself
What does "Wait for replicas" buy you?
- Faster writes
- Every read sees the latest balance
- Cheaper machines
Show the answer
Every read sees the latest balance. A write only counts once the replicas have it. Writes get slower, but no balance is ever behind.
Why 3 database machines and not 2?
- With 2, a network split can leave both sides acting as primary
- 3 machines are faster
- It's the cheapest option
Show the answer
With 2, a network split can leave both sides acting as primary. With 3, only the side with a majority can be primary, so two can never both take writes.
Someone deletes the wrong table. What saves you?
- The standby
- The read replicas
- A backup
Show the answer
A backup. Every copy receives the delete within seconds. Only a backup goes back in time.