You will understand why a timeout does not mean the operation failed, what a duplicate charge looks like from both sides, and how to build retry logic that is safe by design using idempotency keys.
Picture this: EngineerPrep's billing service calls Stripe to charge a user for a Pro subscription. The HTTP call hangs for 30 seconds and the client throws a SocketTimeoutException . The developer who wrote the retry logic thought: the call failed, so I should try again. That is the natural assumption. It is also the assumption that causes double charges. Here is the uncomfortable truth: the exception tells you what your process observed. It says nothing about what Stripe did. The charge may already be sitting in Stripe's database, captured and complete. So the real question isn't "should I retry?" It's: how do I retry safely when I genuinely don't know whether the first attempt worked? That question has a crisp, well-understood answer. By the end of this lesson you will know it — and you will never look at a retry the same way again.
A timeout describes what the caller observed, not what happened at the remote system. This is the single most transferable idea in the lesson. Read it again and let it settle. When your code times out waiting for a response, three things could be true at the provider's end: 1. The request never arrived — it was lost in transit. 2. The request arrived, was processed, and the response was lost on the way back. 3. The request arrived and is still being processed. From your side of the network, all three look identical: silence followed by a timeout. You cannot tell which one happened. The analogy. You send a letter asking your bank to transfer money. You never get a reply. Did the letter get lost before it arrived? Or did the bank transfer the money and their reply letter got lost? You don't know. Sending a second letter might cause two transfers.…
Scene 1 — The unsafe retry (no key) Step 1. The EngineerPrep billing service sends a charge request to the payment provider. Billing Service ──── POST /charge { userId: 42, amount: $29 } ────► Provider The provider receives the request and begins processing. Step 2. The provider captures the charge successfully. It sends a 200 response back. Billing Service Provider ◄──── 200 OK { chargeId: "ch aaa" } ──────────────── But the network drops the response packet. The billing service never receives it. Step 3. The billing service's 30-second timeout fires. It sees only silence. Billing Service ⏱ SocketTimeoutException — "no response received" At this moment: the card has already been charged. The billing service does not know this. Step 4. The retry fires. A second charge request goes out — with no key, so the provider treats it as a brand-new operation.…