System design · like Stripe

Design a payments system

Take people’s money. Exactly once, even when everything goes wrong.

The interview question

Design a payment system: a shop charges a card, the bank approves it, the money moves.

Here is the simplest version that works. An interviewer doesn’t want the finished drawing. They want to watch you keep it standing while it breaks, one problem at a time.

📱Shop app⚙️Payments📒Balances🏦Card network

Break 1 of 4 · 🔁 Messages repeat

The reply gets lost

The bank charged the card, but the reply never reached the shop. The shop tries again.

Payments charged exactly once: 2 charges for 1 coffee

How do you make trying again safe?

Show the fix

Each payment carries a key; a repeat key returns the first result. The second try finds the key it has already seen and answers with the first result. Nobody pays twice.

📱Shop app⚙️Payments📒Balances🏦Card network🔑Seen keys

Payments charged exactly once: 1 charge, however many tries

Why not the others?

  • Never try again. Then a lost reply is a lost sale, and the customer doesn’t know if they paid.
  • A faster server. Speed doesn’t stop a reply getting lost on the way.

The idea behind it: Idempotency keys.

Break 2 of 4 · 💥 Things break

The bank is down for a minute

The card network stops answering. Every payment in that minute fails.

Payments charged exactly once: 1,200 payments failed

What should happen to payments while the bank is down?

Show the fix

Keep them in a queue, and retry after a short, random wait. Payments wait safely, and the random wait stops everyone retrying at the same instant and knocking the bank over again.

📱Shop app⚙️Payments📒Balances🏦Card network🔑Seen keys📬Retry queue

Payments charged exactly once: All 1,200 went through a minute later

Why not the others?

  • Retry instantly, in a loop. Thousands of instant retries hit the bank together the moment it comes back, and knock it over again.
  • Tell the customer it failed. Most would have worked a minute later. You’d lose the sale for nothing.

The idea behind it: Exponential backoff with jitter.

Break 3 of 4 · 🤝 Must agree

Two servers change a balance at once

Two payments for the same shop land at the same moment. Each reads the balance, adds its amount, and writes it back.

Payments charged exactly once: The shop is missing $40

How do you keep balances exactly right?

Show the fix

Never edit a balance: add an entry for each payment, and add them up. Adding an entry can’t overwrite someone else’s. The balance is the sum of the entries, and every cent has a record. That’s a ledger.

📱Shop app⚙️Payments📒Ledger🏦Card network🔑Seen keys📬Retry queue

Payments charged exactly once: Every cent accounted for

Why not the others?

  • Whoever writes last wins. That’s exactly the bug: the second write silently erases the first payment.
  • Lock the whole database for each payment. It’s correct, but one payment at a time won’t survive a busy day.

The idea behind it: The append-only log.

Break 4 of 4 · 👥 More people

Black Friday: 100× the payments

Shops everywhere have a sale. One Payments server can’t keep up and requests start timing out.

Payments charged exactly once: 38% of payments time out

How does Payments handle 100× the traffic?

Show the fix

Many identical copies, behind a load balancer that shares the work. Payments keeps nothing in its own memory (keys and the ledger live elsewhere), so any copy can take any payment. Add copies as traffic grows.

📱Shop app⚙️Payments📒Ledger🏦Card network🔑Seen keys📬Retry queue⚖️Balancer⚙️Payments

Payments charged exactly once: Every payment through in under a second

Why not the others?

  • One much bigger server. There’s always a biggest server, and when it dies, everything stops.
  • Cache the payments. Every payment is new. There’s nothing to reuse, and money can’t be a stale copy.

Say it in the interview

  1. Start simple: app → Payments → bank, with balances in a database.
  2. Retries are safe because every payment has an idempotency key.
  3. If the bank is down, payments wait in a queue and retry with jitter.
  4. Balances are a ledger: entries are added, never edited.
  5. Payments keeps no state, so it scales by adding copies.

The six forces behind every design

Every break above is one of these. Learn the forces and the moves that answer them, and a design you have never seen stops being new.

👥 More peopleOne computer can only do so much.
🐢 Slow partsDon’t make people wait on the slowest thing.
💥 Things breakServers die and networks drop. Plan for it.
🔁 Messages repeatA message can arrive twice, late, or never.
🗄️ Too much dataMore than one machine can hold.
🤝 Must agreeMoney and safety can’t be “probably right”.

Break it yourself.

The diagram is live: press Break it, watch what goes wrong, and pick the fix. Free, nothing to install.

More designs