Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Idempotence

So "idempotence" can be defined as:

An action, that if performed N times has the same effect as performing the action only once.

Got it, easy enough.

My question is about the subtlety of this definition -is an action considered idempotent by itself, or must you also consider the data being passed into the action?

Let me clarify with an example:

Suppose I have a PUT method that updates some resource, we'll call it f(x)

Obviously, f(3) is idempotent, as long as I supply 3 as the input. And equally obvious, f(5) will change the value of the resource (i.e., it will no longer be 3 or whatever value was there previously)

So when we talk about idempotence, are we referring to the generalization of the action/function like (i.e., f(x)), or are we referring to action/function + the data being passed into it (i.e., f(3))?

like image 832
Didaxis Avatar asked Dec 14 '11 14:12

Didaxis


People also ask

What is a example of idempotent?

In computing, an idempotent operation is one that has no additional effect if it is called more than once with the same input parameters. For example, removing an item from a set can be considered an idempotent operation on the set. In mathematics, an idempotent operation is one where f(f(x)) = f(x).

What is idempotence and how is it used?

Idempotent is where you call the same function with the same value and the result is exactly the same, that is the mathematically definition. If you ever update state then you are not idempotent, that its 'a database update' doesn't change anything.


2 Answers

Suppose I have a PUT method that updates some resource, we'll call it f(x)

Obviously, f(3) is idempotent, as long as I supply 3 as the input. And equally obvious, f(5) will change the value of the resource (i.e., it will no longer be 3 or whatever value was there previously).

This is only obvious is the server implementation is such that PUT respects this idempotent property. In the context of HTTP, RFC 2616 says:

Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request.

Going a bit off topic... In a distributed system like the web, you may also want to consider commutativity and concurrent requests. For example N+1 of the same PUT(x1) request should have the same effect, but you don't know if another client made a different PUT(x2) request in between yours, so while nPUT(x1)=PUT(x1) and mPUT(x2)=PUT(x2), the two sets of requests could be interleaved.

like image 188
Bruno Avatar answered Sep 30 '22 00:09

Bruno


Idempotence requires that the action holds for all values over its domain, i.e., f(f(x)) = f(x) for all x. Another way to think about it is that an operation is idempotent if the composition of the operation with itself is just that operation.

like image 27
Michael J. Barber Avatar answered Sep 30 '22 02:09

Michael J. Barber