The Function Call That Can Run Twice
Subtitle: It reads like local code. It is a network.
- Left column - Local call:
- Two outcomes only: it ran, or it did not
- If it dies, your process dies with it
- No third state to reason about
- Costs nanoseconds, not milliseconds
- Reading a field just reads memory
- Right column - Remote call:
- Third outcome: it ran, reply was lost
- A timeout is absence of news, not a fact
- 'Never arrived' looks exactly the same
- Retry on timeout = at-least-once
- So 'charge this card' can run twice
- Simple difference:
- Local: it ran, or it died with you.
- Remote: it ran, died, or ran unseen.
- The latency lie:
- The syntax hides a round trip
- user.name can cost 40ms, not 40ns
- Forty calls in a loop = forty trips
- The innocuous line becomes the outage
- Exactly-once does not exist:
- No protocol gives it over a network
- Libraries do at-least-once plus dedup
- The dedup window is the real guarantee
- Ask its size before you trust it
The one-clause fix:
- Give the request a key the server remembers, so the second arrival returns the first result instead of doing the work again.
- Honest test - add the latency:
- Inject 200ms into every remote call
- Run one ordinary page path
- See which harmless line times out
Taped rule strip: The resemblance is the defect.
