Idempotent HTTP Methods in REST – Complete Interview Guide
Reviewed by Gurusankar M. · Updated Oct 22, 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.
On this page
Concept Made Simple
Coffee Chat Question
“Which HTTP methods are idempotent and why does it matter?”
Remember It Faster
Mind Map Answer
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.| PUT | POST | |
|---|---|---|
| Idempotent? | Yes | Not inherently |
| Typical use | Create or replace the resource at a URI the client already knows (PUT /users/101) | Create a new subordinate resource where the server picks the id (POST /users), or trigger an action |
| Who chooses the URI? | The client | The server |
| Request body | The full replacement representation | Whatever the operation needs |
| Repeat it 5 times | Same final state as calling it once | Possibly 5 new resources or 5 side effects |
| Safe to retry automatically? | Yes | Only with an Idempotency-Key |
DELETE is idempotent in terms of state, not status code. The first DELETE /users/101 typically returns 204 No Content; repeating it usually returns 404 Not Found because the user is already gone. The responses differ, but the server ends up in the same state either way (user 101 doesn't exist), and that end state is what idempotency measures.
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" }- 1. Generate
- Client generates a unique idempotency key per logical operation
- 2. Receive
- Server receives the request with the Idempotency-Key header
- 3. Check
- Server checks whether that key was already processed (Redis, DynamoDB, or a relational table — key → result)
- 4. Process
- If not processed yet, the server executes the operation
- 5. Store
- The result is stored against the key
- 6. Replay
- If the same key arrives again, the server returns the stored result instead of re-executing
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.
Learn by Doing
Hands-on Keyboard
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.Think Beyond the Expected
What If?
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:
- GET, PUT, DELETE are idempotent
- POST is not inherently idempotent
- PATCH depends on the implementation
- Safe and idempotent are different properties
- DELETE stays idempotent even if the 2nd call returns 404
- Idempotency-Key makes POST safely retryable
- Persist the key atomically before processing
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
- What does idempotent mean in REST?
- Which HTTP methods are idempotent?
- What is the difference between Safe and Idempotent?
- Is DELETE idempotent if the second request returns 404?
- Can PATCH be idempotent?
- Why is POST not inherently idempotent?
- How can POST be made idempotent?
- What is an Idempotency-Key?
- Why is idempotency important in distributed systems?
- Why is idempotency especially important for payment APIs?
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?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair