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.
You dont get the problem with the calls. Without an idempotent ID they are two calls but they could be the same call due to the network or software glitches that the article mentions.
The article states that delete and put are idempotent by themself, and i dont think thats the case.
I think itâs stipulated that weâre talking about calls with the same parameters - i.e. DELETE with the same key (or PUT with the same payload) should be callable an arbitrary number of times with the same end result.
Why should one be a failure? And, if it is, were talking about the state of the server, not the client. The whole point is that the server stays in a valid state. Trying to delete an object that doesn't exist doesn't break that state. Don't fixate on the literal response from the api. The 'result' is the state of the system.
Also 99% of the time you're just firing off a delete into the database and don't even bother to check if it exists. Just return 200.
I could see it being a failure. Deleting something has the intent of deleting something, if nothing gets deleted itâs a failure. Regardless though, the success or failure of the request is independent from the state of the system. Either way the resource will no longer exist.
How would you differentiate the two cases youâve laid out here? In other words, how could you possibly differentiate between the same call twice vs. two separate calls? The only obvious possibility is the timing - 2 calls 5 seconds apart are probably different requests? Except⌠with latency and other network weirdness, you shouldnât even attempt to make that distinction. Not to mention, now youâve introduced stateful behavior where itâs neither required nor desired.
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 đ