Idem-what-now?

Idempotenc(y|e) describes an action that will only cause a desired effect once, regardless of the number of times that the action is performed. A kind of janky physical analogy is mowing the lawn. Once you cut the grass, the grass is short and running the lawnmower over it again will not make it shorter. In software systems, we can use this property to simplify error handling in certain contexts. Knowing that a result will not change also allows us to use caching layers effectively and reduce system load.

Restaurant Example

Imagine an ordering system at a restaurant where there is unreliable communication between the kitchen and the tables.

If we don’t receive the ACK from the kitchen (“Got it!”), then what do we do? We shout again!

After ten minutes, 20 gyozas arrive at the table. Oops.

We can fix this by adding in some questions to the kitchen after the lack of acknowledgement of the order:

This readback approach will work, but we have added more noise to the kitchen and more complicated ordering for the table.

Instead, we can choose to make the initial request idempotent, through the usage of a unique Identifier. If the kitchen has already seen the order id before, it just responds that it is on the way. Otherwise, it acts on the order and gets cookin’.

Now handling a lost order is as simple as repeating it until we get our response back.