What does “Idempotent” mean in software?
I had never heard the word “idempotent” when I started at my first software job. I had a liberal arts education and had been working in nonprofit and school management before my career change. I suspect I’m not alone in this total lack of awareness of the concept! So let’s talk about it.
What does it mean?
It means you can do the same thing with the same inputs any number of times, and it won’t change the end result.
This is easy to achieve when we’re talking about data retrieval — retrieving data doesn’t change the data itself. But it gets a little more complex when we’re talking about running operations on data. In that context, another way to phrase the definition of “idempotent” would be that results are changed only the first time an operation is run, and any subsequent runs of the same operation will have no impact.
Let’s look at some examples of this to make it a bit more clear:
- Any GET request where you’re retrieving data is idempotent. If the data changes between requests, it’s because some other operation elsewhere in the system caused it to change, but your requests had no bearing on that at all
- Sorting is idempotent — sorting a collection the first time will put it in order, but if you run the sorting operation again, it will have no impact. The collection will still be in sorted order.
- In the context of data streaming, where you’re consuming data from a message…