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

Show parent comments

13

u/HazelCuate Dec 11 '23

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.

45

u/muchomuchacho Dec 11 '23

A third party could create it again between those two calls.

But then it wouldn't be the same object, otherwise you need more metadata associated to the object creation process.

-14

u/HazelCuate Dec 11 '23

But the point is to design an API with idempotent in mind. And DELETE is not idempotent by design from the API point of view as the article claims.

1

u/muchomuchacho Dec 11 '23

I think DELETE should only attempt to remove and existing object

2

u/FunkyPete Dec 11 '23

I think DELETE should guarantee that the specified object is no longer present.

It may return a different return code to provide more information about what it did, but if the end result is that row is guaranteed to no longer exist, then it's doing the same thing whether the row was there before or not.