Medium๐Ÿ‘ค 3-5 years๐Ÿ‘ค 8-15 years 4 min read Updated Aug 24, 2026

Idempotent HTTP Methods in REST โ€“ Complete Interview Guide

Reviewed by Gurusankar M. ยท Updated Aug 24, 2026

Asked inAmazonDeloitteAccenture
#idempotent#idempotency#http methods#safe methods#put#delete#post#patch#idempotency-key#rest
Report issue

โšก 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.

MethodIdempotent?Safe?Explanation
GETYesYesReads a resource without changing intended server state
PUTYesNoRepeatedly replacing a resource with the same representation has the same intended effect
DELETEYesNoRepeating deletion does not further change the intended resource state
POSTNot inherentlyNoRepeated requests can create multiple resources or trigger repeated effects
PATCHDepends on implementationNoIdempotency 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.

http
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.
http
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.

http
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.
http
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.

text
Client
  |
  | POST /payments
  v
Server processes payment
  |
  | response lost / timeout
  v
Client retries
  |
  | POST /payments
  v
Potential duplicate payment
http
POST /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
text
Idempotency-Key
        โ†“
Lookup existing result
        โ†“
Already processed?
   โ†™             โ†˜
 YES             NO
  โ†“               โ†“
Return result   Process request
                  โ†“
              Store result

Simple 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

http
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:

โœ“ 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

  • 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

Idempotency-KeyRedis SETNXDB unique indexStripe idempotencyRFC 9110

๐Ÿ“š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?

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.

Related Questions