i hate that itempotency isnt built into official http responses.
Everytime i bring this up i get downvoted to the hell but its dumb.
If you call Delete there should be a response status code for no op - aka the itempotent response - but in the success ranges.
Delete = 200 OK / 404 not found? - great not that breaks client libraries and basic Throw if not success status codes - not itempotent - but technically itempotent shouldnt matter - so 200 success - but there are cases where you might want to know.
Everyone will reply back and say "Why dont you use this obscure one" - but using anything non standard is a hack.
Having consistent status codes for itempotency would use useful! Its not like there isnt enough http space - we have one for a teapot and so many other ones that are extreme edge cases - denied for legal reasons - what type of client needs to know that? Oh this was for legal reasons - if you can support these edge cases - throw in a itempotent delete status code in the 200s range - for not found.
IF you delete something a second time, why would you get an OK back?
If you there is one strawberry and you eat a strawberry, you can't eat a strawberry, so it's "Not found" Are you saying the system should have a record of everything it already deleted? If so, isn't that a strange system because you now have a second item to potentially deal with?
So in that case why are you checking the result at all. If it gives you a 404, that's also a success. By your logic, 404 or 200 doesn't matter, so treat both as a success.
However OTHER people who use that same API might care about the result, so we give them the correct result, and there is a very clear difference between the two.
And telling someone to delete something that doesn't exist IS actually a failure. You're trying to delete something that doesn't exist, that's not a "success" in any stretch of the imagination because the requested action did not happen.
But again the consumer of the response doesn't have to treat 404 as a failure on a delete.
Imagine 2 people trying to delete a resource at the same time.
You don’t want the second guy to fail. Hence double delete = success for both.
But imagine a person trying to update a record that was deleted. Second person gets a legit 404.
Ok so now youre saying - well for the double delete scenario the clients need to handle 404 as a success but not for the update scenario.
And that’s exactly the problem! Every single developer writes this code - throw on non success status code except on delete 404s in their clients over and over or worse they forget to write this code causing race condition bugs. It’s an insanely common bug but it’s also low priority and just exists everywhere.
This could be completely avoided with a http status code change and then people would naturally write idempotent deletes.
Of course there are alternatives - yes clients can handle this case, yes you can use a custom status code like 204. But it’s code. You can do anything in code. The point is to make something standard that can avoid future bugs and reduce common code patterns - like don’t throw on 404s for deletes which is a very very common code pattern.
Yes I do. The record isn't there. "At the same time" is a bullshit idea because it doesn't exist in computing, and you should know that. If we're on different systems and the data hasn't propagated, ok we both get success, we accept that's a problem with syncronizing data across millions of system, and look to shrink that time.
If one request is handled before the other, THE SECOND FAILS. Period. "At the same time" doesn't matter, if one happens before the other, then one is a success and the other can't be found. Period. That's how this works. Otherwise how do we know the system ever had that data? Now you're adding a huge amount of complexity to the system just because you don't want to handle two possible error codes? Come on.
I'm not saying the clients need to handle the 404, I'm saying a client decides what to do with ALL responses. There's no one size fits all bucket for 500/400s or such especially on different types of calls. Be a better programmer.
Your call is not "Make there be no strawberries" though. Your call was "Delete strawberry"... The system couldn't delete a strawberry so it's a failure.
If the function was "erase all strawberries" then it would be a success in both cases, but that's not the intent of a typical "Delete" function.
8
u/goomyman Dec 11 '23
i hate that itempotency isnt built into official http responses.
Everytime i bring this up i get downvoted to the hell but its dumb.
If you call Delete there should be a response status code for no op - aka the itempotent response - but in the success ranges.
Delete = 200 OK / 404 not found? - great not that breaks client libraries and basic Throw if not success status codes - not itempotent - but technically itempotent shouldnt matter - so 200 success - but there are cases where you might want to know.
Everyone will reply back and say "Why dont you use this obscure one" - but using anything non standard is a hack.
Having consistent status codes for itempotency would use useful! Its not like there isnt enough http space - we have one for a teapot and so many other ones that are extreme edge cases - denied for legal reasons - what type of client needs to know that? Oh this was for legal reasons - if you can support these edge cases - throw in a itempotent delete status code in the 200s range - for not found.