3

So it's clear for me what idempotence means based on this Defining Idempotence

But I also heard a lot people describe such behavior as deduping. Is that an equivalent terminology?

For example, if an API is idempotent that same request being processed for N times will get the state same as one time. Can I say that API is deduping requests?

Long Quanzheng
  • 2,076
  • 1
  • 10
  • 22

1 Answers1

3

The two terms are not equivalent, though it may be helpful for people unfamiliar with idempotency to think of it initially based on its similarity to deduplication.

For a contrasting example, consider an API for a bank account which accepts a positive or negative number by which to adjust the account balance (deposit or withdrawal). Clearly this API is not idempotent, because consecutive transactions have a cumulative effect.

On the other hand, we would certainly want to deduplicate these transactions. If transaction #123 is (erroneously) submitted twice, it should apply to the account balance only once. In this case, transactions should be deduplicated because the API is not idempotent.

Deduplication is an activity: an action to perform. Idempotency is an attribute: a property to describe. A similarity exists between the two when the result of deduplication is the same as the effect of idempotency; that is, no change in state. But an equivalent outcome does not make the two terms equivalent.

jaco0646
  • 15,303
  • 7
  • 59
  • 83
  • Thanks! I really love the last part "Deduplication is an activity: an action to perform. Idempotency is an attribute: a property to describe." Now I am wondering, can I say deduplication is a method of implementing idempotency? In your example, we could add a "requestID" field in the API and let the API become idempotency so that transaction#123 submitted with the same requestID twice will not change the final state. – Long Quanzheng Nov 16 '20 at 01:41
  • No, while deduplication can be a method of preventing state change, it can also be a method of causing state change (e.g. deduplicating a List). The latter has nothing to do with idempotency. And idempotency does not prevent anything. It describes an effect. Preventing a method from executing is not the same as executing it twice with the same effect. – jaco0646 Nov 16 '20 at 02:02