What does idempotence mean in programming?
NicolasBrondinBernard
Even if the word sounds scary, you'll see that the concept is simple to understand!

Article published on 09/02/2021, last updated on 10/08/2026
This complex term, straight from the world of mathematics, actually holds a very simple meaning to define.
An operation is said to be "idempotent" if it can be repeated as many times as desired and the state of the output data no longer changes after the first execution.
Let's take a simple mathematical example: the absolute value of a number will always be positive, so if we have a negative number as input, it will be transformed the first time it goes through the function.
But if you take this result and pass it back into the "absolute value" function, the result will no longer change, because it is already positive, and this even if you repeat the operation infinitely!
We can say that the operation is idempotent because abs(x) === abs(abs(x)) === abs(abs(abs(x))) etc, etc...
In practice
In algorithmics, it may sometimes be specified that the function to be written must be idempotent for technical reasons, but as soon as we deal with data, especially through HTTP calls, idempotence is an essential best practice.
HTTP and idempotence
REST APIs are very good use cases for presenting this concept because they are based on HTTP calls, and some of this protocol's methods are specified as needing to be idempotent.
The GET, PUT and DELETE methods must not modify the state of the data if they are called multiple times (with the same parameters); the return code may change, but not the state of the data.
Examples:
- A GET request should always return the same data without making any modification
- Several PUT requests containing the same parameters will always modify the same object in the same way, not altering the state of the data after the first time
- The first DELETE request will delete the data in question, and if we send the same request again, the resource will already have been deleted and will only return a 404 error
As for the POST method, it must not be idempotent because we want to be able to potentially save the same data multiple times for various reasons.
There you go, you now know the meaning of this word as well as some best practices regarding the handling of HTTP requests!
No spam. Only free content, news, and ever more resources to level up your skills!
Join +1500 developers
No comments yet