Bugpit

Lessons › Big architectures

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 level

Part 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.

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?

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?

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?

Show the answer

A backup. Every copy receives the delete within seconds. Only a backup goes back in time.

Try it yourself

More in Big architectures

← Live match: a goal in the final Card fraud: a verdict in 100 ms →