Skip to main content
Web DevAPIs & NetworkingDiagramIntermediate

Idempotency

KO: 멱등성 (Idempotency)·EN: Idempotency·JA: 冪等性(Idempotency)

An API and system design property guaranteeing that executing the same request once or multiple times due to retries produces the exact same final state

Table of Contents

Structure Diagram

Idempotency-Key Deduplication & Cached Replay FlowTap a node
Incl. RetrNot FoundAlready SePOST /pay…Key Store…New Key: …Duplicate…
ROOTPOST /pay + Key
1 link
Quick Answer

What is Idempotency?

An API and system design property guaranteeing that executing the same request once or multiple times due to retries produces the exact same final state. It is a core concept in APIs & Networking within Web Dev.

Core Principles

In distributed networks, timeouts leave clients unsure whether a request failed before reaching the server or succeeded right before the response dropped. Idempotency guarantees that safely retrying the exact same operation produces the same system state as executing it once.

While HTTP GET, PUT, and DELETE are designed to be idempotent, POST mutations (payments, transfers, order creation) are not. Production APIs solve this by having clients send a unique Idempotency-Key header (typically a UUIDv4). The server persists the key and response so any retry replays the original result instead of executing the mutation twice.

Practical Takeaways

  • Guard against concurrent duplicates: A double-click can send two identical requests milliseconds apart. Claim the key atomically via a unique DB constraint or lock (IN_PROGRESS state) before running side effects.
  • Validate request payload consistency: If the same Idempotency-Key arrives with different parameters (e.g., a different payment amount), reject it with 422/409 to catch client bugs.
  • Commit atomically: Save the idempotency record and the business mutation inside the same ACID transaction so crashes never leave half-applied state.

Notable Examples

  • Stripe & payment gateways: Retrying a timed-out charge request returns the original receipt without double-charging the card.
  • Webhook and queue consumers: Tracking processed event_id keys to make at-least-once event pipelines safe against duplicates.