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, Hanno was not mean, but rather funny, so let's take his talk as an opportunity to talk about idempotence in web applications. I'm really curious, so let's (mis-) use dev.to's like system as a poll:
Do you know what "idempotent" means or - after checking out wikipedia - used the concept in your projects?
Sometimes idempotent requests to the server are required and obvious, but other times it might be tricky ...or not required at all:
-
dev.to's like buttons don't seem to be idempotent at first, because clicking once activates the like, clicking twice deactivates the like. You might think that the request is just a toggle. But it's not. Each request contains an action ("create" or "destroy"). So the 1st click produces:
{"result": "create", "category": "like"}. And this request is idempotent, because if something goes wrong on the network layer and the server receives this request twice it will still do the right thing, it will activate the like on the 1st request and do nothing on the 2nd request. -
Medium's clapping system is not idempotent. A request looks like this:
{"userId":"my123id456","clapIncrement":1}. And you can also see that it's not idempotent, because clapping once turns the counter from $old-value to $old-value + 1, while clapping twice turns it to $old-value + 2. But in this case it's not a bug, you are explicitly allowed to clap multiple times.
Please vote:
- heart/like = yes, I already knew what "idempotent" means or used the concept in past projects.
- unicorn = no, this is new to me or I've seen no need to implement this concept in my projects.
I for myself must admit, that I've learned the term only 2 or 3 years ago. However I knew its concept and have used it for more than 10 years in past projects. I guess the poll is pretty anonymous (maybe with the exception of the dev.to admins), so please vote with honesty.
By the way: 35c3 is one of the largest hacker events in the world and the talks are streamed live. You will also find recordings of the talks later behind this link.
// cover photo by Yves Sorge / CC BY
Oldest comments (17)
wait... it's not item potent? my world is shattered
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.
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. :-)
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 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.)
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
I was aware of the concept but not the word. Great post!
I'll never forget when I had a senior say "you need to make that an idempotent route".....
Follow up poll: can you pronounce it? 😊
In 7 languages