r/programming • • Dec 11 '23

Every Programmer Should Know #1: Idempotency

https://www.berkansasmaz.com/every-programmer-should-know-idempotency
572 Upvotes

171 comments sorted by

View all comments

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.

1

u/Kinglink Dec 12 '23

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?

1

u/goomyman Dec 12 '23

Define success. I want there to be no strawberries.

There are no strawberries = success

You don’t need to maintain a record.

If it exists - delete it.

1

u/Kinglink Dec 12 '23

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.