How to ensure idempotence

Dwen
Level Up Coding
Published in
7 min readDec 1, 2022

--

Photo by Simon Wilkes on Unsplash

Definition of idempotency.

The concept of idempotence comes from mathematics, which means that the results of N transformations and 1 transformation on the data source are the same.

In the project, idempotence is used to indicate that the results of one request or multiple requests initiated by the user for the same operation are consistent, and there will be no side effects due to multiple clicks.

  • Idempotence includes side effects on resources when the first request is made, but subsequent requests will no longer have side effects on resources.
  • Idempotency focuses on whether subsequent multiple requests have side effects on resources, not on the results.
  • Problems such as network timeouts are not in the scope of idempotency.
  • Idempotency is a kind of commitment of system services to the outside world, rather than realization. It promises that as long as the call interface is successful, the impact of multiple external calls on the system is consistent.
  • A service declared as idempotent will assume that external call failures are normal, and there must be retries after failure.

Scenes to be used.

During business development, you may encounter a situation where the request cannot be received due to…

--

--

I'm an independent entrepreneur, a developer and a father, enjoys speaking, writing, and sharing.