Search Psychevus

12 results available.
↑ ↓ to navigate ↵ to open · esc to close

Lab instrument / Reliability

What happens when a request is sent twice?

A client places one order. Break the network in one of four ways, add defences, and follow every message. The question is never whether the request arrives — it is how many orders exist afterwards, and whether the client knows.

A deterministic teaching model: the same setup always produces the same run. Nothing is sent anywhere.

Inject a fault

Duplicate order

Orders in the store
2
What the client believes
Sees order #2 confirmed and believes it is the only one.
6/6
6 steps. Drag the slider or replay to follow them one at a time.
  1. Client to Server: POST /orders. Attempt 1 asks for an order of 2 items.
  2. Server to Store: save order #1. Order #1 (2 items) is written.
  3. Server to Client: 201 Created — lost. The reply never reaches the client. From the client’s side this looks exactly like a request that never arrived.
  4. Client to Server: POST /orders. Attempt 2 asks for an order of 2 items.
  5. Server to Store: save order #2. Order #2 (2 items) is written.
  6. Server to Client: 201 Created · order #2. The client receives confirmation of order #2.

The customer now has 2 orders.

A timeout does not mean the request failed. The retry was a second request for the same order, and the server had no way to know.

What this relies on

  • Retries need a limit, backoff and jitter. Without them, retries from many clients can turn a brief slowdown into an overload.

Duplicate order. The customer now has 2 orders. Orders saved: 2.

Add defences

A timeout is an unknown, not a failure

Two failures that look the same

When a request times out, the client cannot tell whether it was lost on the way in or whether the work was done and only the reply was lost. Run both faults with retries on and no key: the first is repaired by the retry, the second becomes a duplicate. Same symptom, opposite consequence.

Not retrying does not solve this. It hands the same unknown to a person, who presses the button again.

What a key actually guarantees

An idempotency key names the intent, not the attempt. The client creates it once per order, before the first attempt, and sends it with every retry. The server stores the result under the key and returns that result for every later attempt — so a retry becomes safe because it can no longer be a new request.

HTTP already defines some methods as idempotent. A POST that creates an order is not one of them; the key is how an API makes it behave as one.

Where keys still fail

Races. Checking whether a key exists and then writing it is two steps. Two concurrent attempts can both pass the check — try the double submit with a key but without the create-only claim. Claiming the key must be one atomic write that fails if the key already exists.

Reuse. If the person edits the order and the retry reuses the key, a plain replay answers a request that was not asked. Storing a fingerprint of the request turns that into an explicit conflict.

On this site

The contact form follows the same design. Each message carries a request ID; the server claims a receipt for it with a create-only write, keeps a keyed fingerprint of the message, replays the original receipt for a repeated submission, and returns a conflict if the same ID arrives with a different message. Receipts expire after a day.

The model leaves out retry storms, clock-based expiry and queues that redeliver messages; the reasoning is the same, the failure shapes differ.

Sources and further reading

  1. Making retries safe with idempotent APIsAmazon Builders’ Library
  2. Timeouts, retries, and backoff with jitterAmazon Builders’ Library
  3. The Idempotency-Key HTTP Header FieldIETF HTTPAPI working group, Internet-Draft
  4. RFC 9110 §9.2.2 — Idempotent methodsIETF, HTTP Semantics, 2022
  5. Idempotent requestsStripe API reference
  6. Implementing Stripe-like idempotency keys in PostgresBrandur Leach

Let’s make a connection.

Working on something in software architecture? The contact form will start with that topic selected.

Discuss this challenge
YOUR VISIT, YOUR CHOICE

Privacy, by intention.

You decide what stays on your device. You can change your choice at any time.

Essential

Saves your privacy choice. Administrator sign-in uses a secure session cookie.

Always on
Full privacy notice ↗