Idempotency

A colleague referenced the Microsoft Restful API Guidelines, which require put and delete to be idempotent.

Say what?

I’m more used to thinking of functional programming being idempotent. I.e., the square root of 2 is always the square root of 2, no matter how many times you calculate it.

That kind of operation is idempotent. But the definition of of idempotency is actually looser:  multiple executions of the same operation result in the same state as a single successful execution.

Put another way, there is no difference in executing a particular idempotent operation once or a jillion times.  Which is not to say that there is no difference resulting from how its execution is interleaved with other operations: the outcome of “PUT 2;  PUT 1; PUT 2;” differs from “PUT 2; PUT 2; PUT 1;”

The classic example of an operation that is not idempotent is depositing an amount into an account. If the books are going to balance, this must be done once and only once. But an operation that sets the account to zero will  it always result in a zero balance.

See What is Idempotency?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s