Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Distributed Systems

Why retrying a failed request can make things worse

Retrying a failed request is an obvious safety net, and easy to build backwards. It hinges on one question: did the first attempt actually fail?

Derpx0624 Sept · 3 min read
Contents
Silence is not failureGive each request a unique IDReading can hurt tooRetries pile on at the worst momentThe AI version (it's worse)The rule for the wall
0% read · 3 min leftBack to top ↑
On this page0%
Contents
Silence is not failureGive each request a unique IDReading can hurt tooRetries pile on at the worst momentThe AI version (it's worse)The rule for the wall

Imagine you send a message and get no confirmation. Do you send it again?

If the first one never went out, yes. If it did go out and only the reply got lost, the other person now gets your message twice. You cannot tell which one happened. That is the whole problem with retrying a failed request. It is why the most obvious safety measure is also one of the easiest to get backwards.

Silence is not failure

"Could not connect" means the work didn't happen. A timeout (you stopped waiting and gave up) tells you almost nothing. The request might never have arrived, or been refused, or run completely: saved, charged the card, sent the email, with only the reply lost.

A timeout only tells you that you stopped waiting, not what the other side did. So a naive retry claims something it can't prove, and sometimes you end up with two of something that should exist once.

This failure is silent, and it arrives late

Duplicates rarely show up as errors. They show up weeks later as accounts that don't add up, or a customer with two subscriptions.

Give each request a unique ID

Before sending, make a unique ID for the operation, not for each attempt. Every retry carries the same ID, and the server writes it down next to the result. This is called an idempotency key. Idempotent is a scary word for a simple thing: doing it twice has the same effect as doing it once, like pressing an elevator button (pressing it ten times doesn't call ten elevators).

Python
def create_order(key: str, payload: dict) -> Order:
    existing = store.get(key)
    if existing:
        return existing          # this exact operation already ran

    order = process(payload)
    store.put(key, order)        # same transaction as process()
    return order

Saving the key and doing the work must succeed or fail together, in the same database and the same transaction (one all-or-nothing step). Otherwise there's a moment where the work is done but the key isn't saved, and you've rebuilt the bug. The caller makes the ID, because only the caller knows whether two attempts mean the same thing.

Reading can hurt too

Reading is safe to repeat as far as correctness goes. But the read that gets hammered is usually the expensive one, like a big report or a heavy search. Retrying it three times during a slowdown triples the load on something that's already struggling.

Retries pile on at the worst moment

Think of a slow web page. Everyone hits refresh, so it gets slower. The same thing happens here. A service answers at half speed. Every caller times out and retries, so twice the work hits half the capacity. It slows down more, and more retries fire. This is a retry storm, and the safety net is what stops the recovery.

Service slows
Calls time out
Everyone retries
More load
↺ repeat
A retry storm feeds itself.

Three things keep it in check, and you need all three.

  1. Wait longer each time, with a random wobble. Without the randomness, every caller retries at the exact same moment.
  2. Cap retries as a share of traffic. "Three retries per call" still triples the load across all callers. A budget like retries may not exceed 10% of requests sets a ceiling.
  3. Stop calling for a while. After enough failures in a row, fail instantly for thirty seconds. This is a circuit breaker, like the switch in a house that cuts power before the wiring overheats.
Only retry what could succeed

A "bad request" or "not logged in" will fail again, so don't bother. "Too many requests" or "temporarily unavailable" often tells you when to come back. Follow that advice.

The AI version (it's worse)

All of this gets sharper with AI models, because calls are slow, expensive and often rate-limited (you only get so many per minute). A duplicate costs money. Queues can grow long before anyone notices. And "too many requests" is exactly what a naive retry loop turns into a self-made outage.

If a generated answer is worth saving, it deserves an idempotency key. Turn the question and settings into an ID, and store the answer under it, so a repeat costs just a lookup. You get retry safety and a cache from one mechanism.

The rule for the wall

Retrying is a way of adding more load. It only helps when three things are true.

Doing it twice is provably harmless
The error could succeed next time
Total volume is capped
Miss one and your safety net becomes an amplifier.
Key takeaways
  • A timeout only tells you that you stopped waiting, not what the server did.
  • Use one idempotency key per operation, saved in the same transaction as the work.
  • Back off with randomness, cap retries as a share of traffic, and use a circuit breaker.
  • Only retry errors that could succeed next time, and give costly AI answers a key too.
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Distributed Systems · 6 minHow does your computer know the time? (And why it can be wrong)Distributed Systems · 4 minWhat are CRDTs? How shared documents stay in syncDistributed Systems · 4 minHow does TCP work on bad Wi-Fi?
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)