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.
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.
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.
1. save attempt bk_77 · PENDING_PAYMENTthe intent, before any money moves2. charge €240 · reference bk_77same reference on every ask3a. succeeded → confirm the bookingknown3b. declined → release the roomknown3c. timeout / network error → unknownshow “Confirming your booking…”, keep the hold4. every minute: pending bk_77? ask the providerthen confirm or releaseFourth, 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.
| Owner | When | Starts from | Catches |
|---|---|---|---|
| Recovery job | Every minute | Attempts StayHub wrote down as pending | Timeouts, crashes after the intent was saved |
| Nightly reconciliation | Every night | The provider's list of charges vs StayHub's bookings | Anything never written down: bugs, lost records |
| Graceful deploys | Every deploy | Requests in flight finish before a server stops | Cut-off requests like Tuesday's six |
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.
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 answered1StayHub asked the provider to charge €240 and heard nothing for 8 seconds. What does StayHub know?
2What is a partial failure?
3On the phone, the line goes dead right after you give your card number. What's the safe move?
4Why does Booking save the attempt as pending payment before calling the provider?
5The provider doesn't answer within 8 seconds. What does the new checkout show the guest?
6A deploy restarts servers mid-request. Six guests are charged with no booking, and the error-rate dashboard stays green. Why?
7Why does the nightly reconciliation start from the provider's list of charges?
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?
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?
10StayHub's booking engine design already said "a timeout means unknown". Why was the rule lost?
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 accountEvery 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