jspωiki
Idempotent

Overview#

Idempotent, in computer science, the term is used more comprehensively to describe an operation that will produce the same results if executed once or multiple times.

This may have a different meaning depending on the context in which it is applied. In the case of subroutine calls with side effects, for instance, it means that the modified state remains the same after the first call. In Functional Programming, though, an Idempotent function is one that has the property f(f(x)) = f(x) for any value x

Simply put, an operation is Idempotent if it produces the same result when called over and over. An identical request should return an identical Response when done twice, two thousand, or two million times. The source of most confusion around this concept comes with the idea of identical results, however. What we expect to see is identical results in the return form rather than in the return value.

Idempotent in Information Technology#

Idempotent, in Information Technology, may have a different meaning depending on the context in which it is applied:
  • in imperative programming, a subroutine with side effects is Idempotent if the system state remains the same after one or several calls, in other words if the function from the system state space to itself associated to the subroutine is Idempotent in the mathematical sense given in the definition;
  • in Functional Programming, a pure function is Idempotent if it is Idempotent in the mathematical sense given in the definition.
This is a very useful property in many situations, as it means that an operation can be repeated or retried as often as necessary without causing unintended effects. With non-idempotent operations, the algorithm may have to keep track of whether the operation was already performed or not.

Idempotent Examples#

A function looking up a customer's name and address in a database is typically Idempotent, since this will not cause the database to change.
Similarly, changing a customer's address is typically Idempotent, because the final address will be the same no matter how many times it is submitted.

However, placing an order for a car for the customer is typically not Idempotent, since running the call several times will lead to several orders being placed.
Canceling an order is Idempotent, because the order remains canceled no matter how many requests are made.

More Information#

There might be more information for this subject on one of the following: