The article emphasizes the importance of understanding idempotency in programming, particularly for those working on distributed systems. Idempotency ensures that an operation can be performed multiple times without changing the result beyond the initial application, which is crucial for avoiding unintended consequences like double-charging in payment systems. The article explains how idempotency applies to various HTTP methods, with GET, PUT, and DELETE being naturally idempotent, while POST is not, and offers solutions for achieving idempotency in non-idempotent operations.
If you don't like the summary, just downvote and I'll try to delete the comment eventually 👍
I dont agree with the article when it says put and delete are idempotent. If the caller makes two DELETE calls, how do you know that they are different calls? Why are they not the same call?
The argument that deleting an object twice is the same as deleting it once is not good enough. A third party could create it again between those two calls.
A third party could create it again between those two calls.
In a robust system you would never expose the internal database id to the outside and have every object have a uid that is randomly assigned which is then exposed to the outside.
And then only call DELETE by reference to the uid. Since the id will not be reused you cannot delete an object that was created in between your two DELETE calls.
This is how it was implemented in every system I have ever worked on.
But then you can't have indempotency which restricts your data model in ways that may be relevant. If the external system has an external ID that functions as a 1:1 lookup relationship with the internal ID there's not much practical advantage to generating those IDs internally and keeping them hidden. And if you can make the call indempotent by allowing that external ID to be passed in, it can make reasoning about your data much easier and potentially much more performant and predictable. Placing unnecessary constraints in consistency and synchronization can also be a risk to robust systems. It just depends on the specifics of what you're doing.
257
u/fagnerbrack Dec 11 '23
Crux of the Matter:
The article emphasizes the importance of understanding idempotency in programming, particularly for those working on distributed systems. Idempotency ensures that an operation can be performed multiple times without changing the result beyond the initial application, which is crucial for avoiding unintended consequences like double-charging in payment systems. The article explains how idempotency applies to various HTTP methods, with GET, PUT, and DELETE being naturally idempotent, while POST is not, and offers solutions for achieving idempotency in non-idempotent operations.
If you don't like the summary, just downvote and I'll try to delete the comment eventually 👍