HTTP semantics, caching and delivery · core
HTTP methods, safety, idempotency and idempotency keys
GET and HEAD are safe (read-only); GET, HEAD, PUT, DELETE and OPTIONS are idempotent (repeating them has the same intended effect); POST and PATCH are not, so payments and orders use a client-generated Idempotency-Key so retries and double clicks cannot create duplicates.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Safe = no intended change on the server (GET, HEAD, OPTIONS). Idempotent = doing it twice has the same intended effect as once (all safe methods plus PUT and DELETE).
- Idempotency is about server state, not the response: the first DELETE returns 200 and the second 404, and DELETE is still idempotent.
- PUT replaces the whole resource (idempotent); PATCH applies a partial change (not guaranteed idempotent, e.g. 'add 1'); POST creates or runs an action (not idempotent).
- Only idempotent requests are safe to retry automatically. A timeout on POST /pay means 'unknown outcome', not 'failed'.
- Idempotency key: the client generates a UUID per user intent (not per attempt) and sends it as a header; the server stores the first result for that key and returns it for repeats. Stripe and most payment APIs work this way.
- UI side: disable the button while pending, show a pending state, and reconcile with the server's final state; but never rely on the UI alone.
The red pen
Common traps: mistake → fix
Mistake: "Disabling the Pay button prevents double charges"
Fix: retries, network replays, two tabs and double-taps on slow phones still happen; the server needs an idempotency key.
Mistake: "PATCH is idempotent like PUT"
Fix: PATCH is not guaranteed idempotent.
Mistake: "A new idempotency key for every retry"
Fix: the key must stay the same for all retries of one user action.
Mistake: "GET with side effects is fine for simple things like logout"
Fix: GET must be safe; prefetchers, crawlers and CSRF can trigger it.
Easy to hard
Questions interviewers ask, easy to hard
- Which HTTP methods are idempotent? Which are safe?
- PUT vs PATCH vs POST: when do you use each?
- A user double-clicks 'Pay'. How do you make sure they are charged once?
- The pay request timed out. What does your UI show, and what does it do next?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.