Skip to content
Lesson 49

Partial failures

Over a network, a call can succeed, fail, or leave you not knowing. Learn why "payment failed, try again" charged 37 guests twice, and how to build a checkout that never guesses.

The lesson in text

Click a paragraph to hear it.

01Charged, but no booking

Friday, 19:05. The company that charges StayHub's cards, the payment provider, slows down. For 12 minutes, its answers crawl. 140 checkouts give up waiting.

Every one of those guests sees the same message: payment failed, try again. It sounds reasonable, and it's polite. Many of them press Pay again.

At 19:30, Maya brings the count. 37 guests were charged twice. And 9 were charged with no booking at all. Support is drowning.

How can a payment that failed charge anyone? In this lesson, you'll learn the third answer every network call can give, and how to build a checkout that never guesses.

02The line goes dead

Picture ordering dinner by phone. You give your order and your card number. Usually, you hear one of two answers: order confirmed, or sorry, we're closed.

But tonight, right after your card number, the line goes dead. Did they take the order? Maybe they never heard it. Maybe they heard it, charged you, and the cook is already at work. You can't tell.

So you call again and order again. If the first order went through, two dinners arrive, and you pay twice. That's exactly what 37 StayHub guests did.

03Three outcomes

Inside one program, a step either happens or it doesn't. Between two computers, there's a third answer. The request may have been lost on the way. It may have failed over there. Or it may have worked, while the reply got lost or arrived too late.

From your side, all three look the same: silence. So every call across a network has three outcomes: succeeded, failed, or unknown.

Three outcomes of a call across a network
Succeeded
"Order confirmed."
The answer came back: it happened.
Failed
"Sorry, we're closed."
The answer came back: it didn't happen.
Unknown
The line goes dead.
Silence: lost on the way, failed over there, or worked while the reply was late.
Inside one program a step happens or it doesn't. Between two computers, silence is a third answer, and a timeout only ends your wait: it doesn't undo what the other side did.

A timeout is how long you wait before you stop waiting. StayHub waits 8 seconds for the provider. But giving up doesn't undo anything on the other side. The charge may still be going through.

This is a partial failure: some parts did their job, others didn't, and no single part knows the whole truth. Engineers at Sun Microsystems listed it as the first false belief about networks, back in the nineties: the network is reliable.

And it's not only payments. Telling a hotel about a booking, the relay copying an event into Kafka, sending a guest an email: every call across a network can end in silence. Payments just make the wrong guess expensive, and very visible.

04What Friday did

Back to Friday. The provider was slow, not down. Many of the 140 charges went through, just after StayHub stopped waiting. StayHub's code called every one of them failed.

Guests who pressed Pay again were charged a second time: 37 of them. Guests who gave up kept the first charge, but their room was released: 9 paid for nothing.

Friday 19:05: unknown treated as failed
Guest
StayHub checkout
Payment provider
Pay €240
charge €240
8 s, no answer → “Payment failed, try again”
charged ✓ (too late: nobody is listening)
Pay €240 again
charge €240 → second charge
The provider was slow for 12 minutes; 140 charge calls hit the 8-second timeout. Many charges went through anyway. The old code said “payment failed, try again”: 37 guests paid twice, 9 paid with no booking.

The strange part: StayHub knew this rule. The booking engine design said it clearly: a timeout means unknown. But when checkout moved into its own service, the new code caught every error the same way, and showed payment failed.

The rule lived in a design document, not in the code, and not in a test. When code is rewritten, a rule that no test checks is easy to lose.

05A checkout that never guesses

Back to the phone. The careful way: before you call, write a note on the fridge. Dinner from Luigi's, ordered under your name. If the line goes dead, you don't order again. You call back and ask: do you have an order under my name?

StayHub's new checkout does the same, in four steps. First, write down the intent. Before any money moves, Booking saves the attempt as pending payment, with a reference, bk_77.

Second, charge with that reference. If StayHub ever asks again with the same reference, the provider knows it's the same payment, and charges once. The next lesson goes deeper into that.

Third, sort the answer into three. Succeeded: confirm the booking. Declined: release the room. Timeout or network error: unknown. And for unknown, tell the truth: confirming your booking. The room stays held.

A checkout that never guesses
1. save attempt bk_77 · PENDING_PAYMENTthe intent, before any money moves
2. charge €240 · reference bk_77same reference on every ask
3a. succeeded → confirm the bookingknown
3b. declined → release the roomknown
3c. timeout / network error → unknownshow “Confirming your booking…”, keep the hold
4. every minute: pending bk_77? ask the providerthen confirm or release
The reference (bk_77) lets the provider recognise a repeat and lets the recovery job ask about this exact payment. On Friday's 140 timeouts, the job found 46 charged (confirmed) and released the other 94.

Fourth, find out. A small recovery job runs every minute. It looks for attempts still pending, asks the provider about each reference, and confirms or releases.

Replay Friday with this checkout. The 140 timeouts become 140 confirming screens. A minute later, the job learns that 46 were charged, and confirms them. The other 94 are released. No double charges. Nobody pays for nothing.

The price is honest: on a bad evening, some guests wait a minute for their answer, and the team runs one more job and watches it. For money, that's a fair trade.

06The crash nobody saw

A timeout isn't the only gap. The following Tuesday, at 14:10, before the new checkout shipped, a deploy restarted the servers one by one. Six requests were cut off between charging the card and saving the booking.

The dashboard stayed green. A program that is stopped mid-request writes no error. Three days later, Ana arrived at her hotel in Lisbon. The hotel had never heard of her, and it was full.

Error rates count errors. They don't count wrong data. So the new checkout has three more defences. The intent written first turns a silent loss into a visible to-do, which the recovery job finds. A deploy now lets requests in flight finish before a server stops.

And every night, a reconciliation compares the provider's list of charges with StayHub's bookings, and alerts on any gap. It starts from the provider's side, so it even catches what StayHub never wrote down. That's checking your bank statement at the end of the month.

Every half-finished state has an owner
OwnerWhenStarts fromCatches
Recovery jobEvery minuteAttempts StayHub wrote down as pendingTimeouts, crashes after the intent was saved
Nightly reconciliationEvery nightThe provider's list of charges vs StayHub's bookingsAnything never written down: bugs, lost records
Graceful deploysEvery deployRequests in flight finish before a server stopsCut-off requests like Tuesday's six
Error rates count errors, not wrong data: Tuesday's six charges with no booking left the dashboard green. Ana found out at a full hotel in Lisbon, three days later.

07How long to wait

At the design review, Maya pushes back. Confirming for up to a minute? Guests hate that. Wait 30 seconds, and give them a real answer.

Omar does the math. Booking runs on 4 servers with 50 workers each: 200 in total. At the Friday peak, 2 checkouts arrive every second. Waiting 30 seconds keeps 60 workers stuck, plus every guest who clicks again. And search and login share the same workers.

How long to wait: the arithmetic
8 s, then “confirming”
2 checkouts/s × 8 s = 16 workers waiting at worst
184 left for search, login and the rest
30 s for a final answer
2 checkouts/s × 30 s = 60 workers stuck, plus re-clicks
and some calls still time out: unknown again
Booking has 4 servers × 50 workers = 200, shared with search and login. A longer timeout makes unknowns rarer, not impossible, and turns a slow provider into everyone's problem. The team kept 8 s, then “confirming” and the recovery job.

And a longer wait doesn't remove the unknown. It only makes it rarer, and more expensive each time. So the team keeps 8 seconds, then shows confirming, and lets the job finish. Maya gets a clear page and a confirmation email for those guests.

One more rule: always set a timeout. A call with no timeout can wait forever when the other side hangs, and every worker that waits is one fewer for everyone else. No answer at all is worse than an honest unknown.

08Your job as lead

You ask Claude Code to handle payment errors. It wraps the charge and the confirm in one try, and in the catch it returns: payment failed, try again. Its summary says: errors are now handled.

That catch is Friday, in code. It turns I don't know into failed. Ask for the intent saved first with its reference, timeouts treated as unknown, the confirming screen, and the recovery job. Then ask for two tests: a timeout after the charge went through, and a crash before the confirm. Each must end with one charge and one booking.

For every call that crosses a network, ask four questions. If it times out, could it have happened anyway? What does the user see meanwhile? Who finds the half-finished ones? And how would we notice wrong data while the dashboard is green?

Let's recap. A call across a network can succeed, fail, or leave you not knowing. A timeout ends the wait, not the work. Write the intent first, tell the truth while you find out, and give every leftover an owner: a job every minute, a check every night. Next: a guest books a room, refreshes the page, and her booking has vanished.

Check yourself

0/10 answered
  1. 1StayHub asked the provider to charge €240 and heard nothing for 8 seconds. What does StayHub know?

  2. 2What is a partial failure?

  3. 3On the phone, the line goes dead right after you give your card number. What's the safe move?

  4. 4Why does Booking save the attempt as pending payment before calling the provider?

  5. 5The provider doesn't answer within 8 seconds. What does the new checkout show the guest?

  6. 6A deploy restarts servers mid-request. Six guests are charged with no booking, and the error-rate dashboard stays green. Why?

  7. 7Why does the nightly reconciliation start from the provider's list of charges?

  8. 8Maya proposes waiting 30 seconds for the provider instead of 8. Booking has 200 workers, and the peak is 2 checkouts a second. What's the risk?

  9. 9Claude Code wraps charge and confirm in one try, and the catch returns "Payment failed, try again". It says "errors are now handled". What do you ask for?

  10. 10StayHub's booking engine design already said "a timeout means unknown". Why was the rule lost?

Free account

Save your progress — create a free account

Free. No card. Your finished lessons follow you to any device, and you can ask questions in the community.

Create my free account
Founding members

Every lesson is free while we build. Lock in €9/month for later.

The first 100 members keep the founding price for as long as they stay. Reserving is free: no card, nothing is charged.

See the founding offer

Questions from the community

All questions →