In a very good talk about TLS 1.3 at 35c3 Hanno Böck wondered if web developers know what "idempotent" means. Now before you fall into a rage, Hann...
For further actions, you may consider blocking this person and/or reporting abuse
Follow up poll: can you pronounce it? 😊
In 7 languages
Almost ten years ago it was drilled into my head by the CTO. To this day (and no longer working with him for years) I still fear of him discovering that I didn't make this or that function fully idempotent.
For whatever reason I don't have idempotent in my typical software development vocabulary, even though I know what it means and its conceptual importance. I did implement one of these examples after all.
But I rarely use the word either in speech or in my internal dialog as I'm thinking about things. I certainly use the idea of idempotency, but not the word for some reason.
The REST architecture separates resource representation (the response, the state) from the operation. So, repeated GETs will result in the same operation on the server (so it's idempotent), while the actual state might have changed in time.
Instead repeated POSTs will result in new resources being created, so it's not idempotent
It's slightly different from what you intend
By that definition, I guess I have used the concept, even without knowing the word.
Thank you for introducing the arcane term, that people should be aware of, Thorsten.
I've only heard "of" the term,
Idempotent
and been using functions/methods without knowing what it was 😅1️⃣ First example is SQL server not allowing User-defined functions (UDFs) to call stored procedures (sprocs) as sprocs can have side effects (writing/update database) while UDFs do not allow it (as it needs to be pure).
2️⃣ Second example is in React's
setState
, where it requires to pass a pure function (meaning having no side-effects) to return a new state object instance (for reconciliation optimization).I've only realized that after reading your linked Wikipedia article under Computer science meaning section in which it reads,
I knew the term from a discussion on GitHub (and had to google it back then), but I had used idempotency for years before — just without knowing that there's a word for it. That's probably the case for a lot of, if not most programmers who don't know idempotency.
(FWIW that's one of the greatest advantages of studying Computer Science in my opinion — programmers without a CS background often use the same concepts, but CS people know their names, which is basically a superpower.)
Quick way to tell whether your web app is not idempotent: You use a client-side mechanism to disable (or otherwise obstruct) a submit button once it's been clicked because the same transaction can't be allowed to be submitted more than once. If a transaction can be processed more than once - irrespective of what's happening in the client - the implementation isn't idempotent and is still capable of processing the same thing more than once. It's increasingly rare to see this kind of thing in the wild, but it's still out there.
NB: I am NOT a webdev... at all.
My definition:
f(f(x)) = f(x)
i.e.
applying the same function f() 1 or more times yields identical output (including side effects).
Idempotent has been a well talked about term in DevOps / Systems Automation circles for a while now. It's also quite popular in functional programming, and of course began in mathematics.
My favourite example of a need for an idempotent function was on an old e-commerce site I worked on. Where rather than having a remove line function it used the add to basket function with negative max int. I would have loved an idempotent function rather than having to deal with the side effects caused by a shortcut. Safe, repeatable, no side effects. That's the idempotent dream :)
Another example of idempotency is the REST architecture in which everything but POST should be idempotent. Repeated GETs should yield the same result, same for DELETEs and so on.
I'll never forget when I had a senior say "you need to make that an idempotent route".....
I was aware of the concept but not the word. Great post!
I already knew what "idempotent" meant from a mathematical point of view, but never really thought about how the concept could be used to build "retry-tolerant" systems, so I went for the unicorn. :-)
I only did because of this article from a long time ago
Why you should use standard HTTP methods when designing REST APIs
Suhas Chatekar
wait... it's not item potent? my world is shattered