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
wait... it's not item potent? my world is shattered