Skip to content
EduVerse

Idempotency

Explained

Concept

Also known as: Idempotentie

The property that running an operation several times has the same result as running it once.

Idempotency, explained

Written by EduVerse

What it is

An operation is idempotent when doing it twice has the same effect as doing it once. Setting a user’s email to a fixed address is idempotent; adding ten euros to a balance is not. In HTTP, GET, PUT and DELETE are meant to be idempotent, while POST usually isn’t.

Why teams use it

Networks fail in awkward ways: a request can succeed on the server while the response gets lost, so the client tries again. Message brokers sometimes deliver the same message more than once, too. If your handling is idempotent, those duplicates are harmless; if it isn’t, a customer gets charged twice or receives two of everything.

An example from work

A payment request in your checkout code times out, and your retry logic sends it again. To prevent a double charge, each request carries an Idempotency-Key header with a unique id, and the payment provider answers the retry with the result of the first attempt instead of charging again. Stripe’s API works exactly like this.

Our own explanation, not a quote from the book.

In the book

Sentences from The Software Realm, Decoded that mention Idempotency, exactly as printed.

    2 more passages about Idempotency in the full book

    Read every conversation where Idempotency comes up, with the interactive slides and demos.

    See the book

    Where it fits

    Reliable message processing, API design, retried requests

    Coverage in the book

    Explained

    Explained and compared with alternatives, so you know where and why it’s used.

    Appears in