2

In building a WEB API, sometimes we have naturally idempotent operations (like deleting a given resource) and sometimes not (like paying with a card)

However, you can always use a random number as a transaction ID, to prevent it from happening more then once (see, eg., stripe's idempotency keys: https://stripe.com/blog/idempotency)

Is there a downside to this? Why not do it all the time and forgo non-idempotency forever?

josinalvo
  • 1,366
  • 13
  • 26

1 Answers1

1

This is a really good question to every API designer. I think the downside is the additional effort that required to implement it on both sides. So systems that fail very rarely or systems that are less critical in case of failure or duplicate operation can be developed without idempotency. Keep in mind the YAGNI principle and develop only what is really required. Ask your product or business expert about the failure rate and tolerance to duplicate operations.

Hope this helps

Boris Modylevsky
  • 3,029
  • 1
  • 26
  • 42