Skip to content

Keeping The Operations Idempotent

Idempotent operations are designed such that the effect of the operation is the same, regardless of how many times it is called.

If client application send us a message:

  • the message can be lost
  • the response of the message can be lost
  • the message wasn't recieved as a critical component in our system went down.

This means that if the same request is sent multiple times, the system should behave as if the request was only sent once. Idempotence helps ensure that the API remains consistent and reliable, even in the face of network failures, timeouts, and other issues.

If our operation is idempotent, they can simply resend the same message again without any consequences.

In practice, this means that when designing APIs, developers should ensure that each operation is idempotent by designing the API to handle repeated requests gracefully. This can be achieved by using techniques such as optimistic locking, versioning, and client-side caching.

For example, optimistic locking can help ensure that an operation is only executed once, even if the same request is sent multiple times.

Versioning can help ensure that the API remains backward-compatible, and that repeated requests do not cause unintended side effects.

Client-side caching can help reduce the load on the API, and ensure that the same data is not unnecessarily fetched multiple times.