Idempotent HTTP Methods in REST โ Complete Interview Guide
Reviewed by Gurusankar M. ยท Updated Aug 24, 2026
โก Short Answer
An operation is idempotent when making the same request multiple times has the same intended effect on server state as making it once. GET, PUT, and DELETE are idempotent. POST is not inherently idempotent. PATCH isn't necessarily idempotent โ it depends on what the patch operation does.
โCoffee Chat Question
Concept Made Simple
โWhich HTTP methods are idempotent and why does it matter?โ
๐ง Mind Map Answer
Remember It Faster
Idempotency is about the effect on server state, not about the HTTP response looking identical every time. Calling an idempotent operation once or five times in a row should leave the resource in the same state as calling it once.
| Method | Idempotent? | Safe? | Explanation |
|---|---|---|---|
| GET | Yes | Yes | Reads a resource without changing intended server state |
| PUT | Yes | No | Repeatedly replacing a resource with the same representation has the same intended effect |
| DELETE | Yes | No | Repeating deletion does not further change the intended resource state |
| POST | Not inherently | No | Repeated requests can create multiple resources or trigger repeated effects |
| PATCH | Depends on implementation | No | Idempotency depends on what the patch operation does |
Safe and idempotent are different HTTP properties โ safe does not mean idempotent. Safe means the request isn't intended to modify server state (GET, HEAD, OPTIONS). Idempotent means repeating the same request has the same intended effect on server state, whether or not that request is safe. From the table above: GET is both safe and idempotent; PUT and DELETE are idempotent but not safe (they do change state); POST is neither.
PUT /users/101
Content-Type: application/json
{ "name": "John" }
# Call this 5 times in a row -> user 101 still just has name "John".
# The resource ends up in the same state either way.POST /users
Content-Type: application/json
{ "name": "John" }
# Call this 5 times in a row -> 5 new user resources are created.
# POST is not inherently idempotent - each call has an additional effect.Is PATCH idempotent? It depends entirely on what the patch operation does โ PATCH has no inherent guarantee either way. A replace-style PATCH that sets a field to an absolute value is idempotent. An increment-style PATCH that applies a delta is not.
PATCH /orders/55
Content-Type: application/json
{ "status": "shipped" }
# Idempotent: call this 5 times -> order 55's status is "shipped" either way.
# It sets an absolute value, not a delta.PATCH /accounts/9
Content-Type: application/json
{ "balance": { "$inc": 500 } }
# NOT idempotent: call this 5 times -> balance goes up by 2500, not 500.
# It applies a delta, so repetition compounds the effect.In production, clients don't always know whether a request succeeded. A network timeout can happen after the server already processed the request โ the client only knows the response never arrived, not whether the operation ran. So it retries.
Client
|
| POST /payments
v
Server processes payment
|
| response lost / timeout
v
Client retries
|
| POST /payments
v
Potential duplicate paymentPOST /payments
Idempotency-Key: 8f14e45f-ea...
Content-Type: application/json
{ "amount": 5000, "currency": "INR" }Idempotency-Key
โ
Lookup existing result
โ
Already processed?
โ โ
YES NO
โ โ
Return result Process request
โ
Store resultSimple analogy: setting a thermostat to 22ยฐC is idempotent โ setting it once, or five times, leaves the room at the same target temperature. Compare that to "add โน500 to my account" โ repeating that instruction five times adds โน2,500, not โน500. Same-looking request, very different behavior under repetition โ that's exactly the difference idempotency captures.
โจ๏ธHands-on Keyboard
Learn by Doing
POST /payments
Idempotency-Key: 3f1c-...-9a
{ "amount": 5000, "currency": "INR" }
# Retry with the SAME key -> same 201 response, same payment,
# no double charge. The server recognizes the key and returns
# the stored result instead of processing the payment again.๐ฅWhat If?
Think Beyond the Expected
Is DELETE still idempotent if the second request returns 404 instead of 204?
Yes. First request: DELETE /users/101 โ 204 No Content (resource deleted). Second request: DELETE /users/101 โ 404 Not Found (already gone). The HTTP response differs, but idempotency is about the intended effect on server state โ after either request, user 101 does not exist. The response code is allowed to change; the resulting state is not.
๐Real World
A payment client sends POST /payments, the network stalls, and the client times out without knowing whether the charge went through. Without an idempotency mechanism, retrying risks a duplicate charge. With an Idempotency-Key, the retry carries the same key โ the server recognizes it already processed that operation and returns the original result instead of charging the customer again. This is exactly why banking and payment APIs (Stripe and most payment gateways) require an idempotency key on POST /payments-style endpoints.
๐ฏInterviewer's Expectation
Keywords they're listening for:
โ ๏ธCommon Mistakes
- โSaying "POST and PATCH are not idempotent" as a blanket rule โ POST isn't inherently idempotent, PATCH depends on what it does
- โConfusing Safe with Idempotent โ they're different HTTP properties
- โAssuming idempotent means the HTTP response must be identical every time
- โSkipping Idempotency-Key on retryable POST endpoints (payments, order creation)
- โProcessing the request before persisting the idempotency key, leaving a race window for concurrent retries
โ Best Practices
- โUse PUT for full replacement; it's naturally idempotent
- โAdd an Idempotency-Key to any POST that creates side effects and might be retried
- โPersist the key atomically (DB unique index or Redis SETNX) before processing, not after
- โDocument exactly what a PATCH operation does and whether it's safe to retry
- โJudge idempotency by effect on state, not by whether the response looks the same
๐Follow-up Questions
- 1What does idempotent mean in REST?
- 2Which HTTP methods are idempotent?
- 3What is the difference between Safe and Idempotent?
- 4Is DELETE idempotent if the second request returns 404?
- 5Can PATCH be idempotent?
- 6Why is POST not inherently idempotent?
- 7How can POST be made idempotent?
- 8What is an Idempotency-Key?
- 9Why is idempotency important in distributed systems?
- 10Why is idempotency especially important for payment APIs?
๐งฉRelated Technologies
๐References
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly โ AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Idempotency (REST APIs) Interview question: "Which HTTP methods are idempotent and why does it matter?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
โญ Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission โ at no extra cost to you. It helps keep Full Stack Interview Guru free.