Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I had only ever encountered idempotence in the context of system management (Ansible, Puppet, Chef, etc)

Article made me think it's actually applicable to other management as well



PUT requests are intended to be idempotent, which is one of the things that distinguishes them from POST requests. This (in my experience) is most non-CS-backgrounded software developers' exposure to idempotence, but it actually has tons of value pretty much wherever you can apply it. The ability to (sometimes accidentally) do a thing twice and have it leave no unintended consequence is huge.

UPSERTs can be idempotent as well. "If this doesn't exist, create it, and if it does, update it to match this state", implies that running it twice will leave no unintended side effects.


In the last couple years I've come to realize that nearly all POSTs should actually be PUTs, sometimes with a client-provided uniqueness token in the URL (like a UUID) that becomes part of the newly-created resource's ID.

Now that I think about it, all the situations where I'm fine using POST are also idempotent, such as changing an object's metadata (technically PUT or PATCH), or sending a batch of HTTP requests to an endpoint bundled as a single request.


It's a basic property of HTTP "GET". Or it's supposed to be. "GET" is not supposed to change server site state. That's what "POST" is for. This matters if there's a cache in the middle, since caches tend to assume that GET requests are idempotent and can be served from cache. Cloudflare assumes that. POST requests have to go through to the real server.


Get is idempotent because it's the identity function. It does not change the state of the data. So it's a trivial case of idempotency.

A more interesting function is PUT (idempotent) vs POST (not idempotent)


GET is supposed to be idempotent. But there are sites and APIs where URL parameters make something happen on a GET.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: