What does idempotent mean?
Idempotent means that doing something once produces the same result as doing it multiple times. It’s a property of operations where repeating them doesn’t cause unintended side effects.
A classic example is a DELETE request. If you delete a record with ID 42, the record is gone. If you send that same request again, the record is still gone. The end state is the same whether you ran it once or ten times. That’s idempotent. A POST request that creates a new record every time it’s called is not idempotent, because each call changes the state.
In API design, idempotency matters a lot for reliability. Networks are unreliable. Requests time out. Clients retry. If your API isn’t idempotent, a retry could double-charge a customer, duplicate an order, or create data inconsistencies. Designing operations to be idempotent means retries are safe.
HTTP defines which methods are expected to be idempotent. GET, PUT, and DELETE are all idempotent. POST is not. This is why updating a resource with PUT is preferred over PATCH in some cases. If the update request is sent twice, the result is the same both times.
The word itself comes from mathematics, where an operation is idempotent if applying it multiple times has the same effect as applying it once. In programming, the concept is the same, just applied to functions, API calls, and database operations.
I studied Physics and Math in college, where idempotent shows up regularly. Rounding is a simple example: round 2.7 and you get 3. Round 3 again and nothing changes. Applying the operation twice gives the same result as once. When I first encountered the term in software, it clicked immediately because the underlying idea was the same.