Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 1
    @del: a payment API is an excellent example, since it shows: if an API does things which may cause trouble when operations are processed twice, it usually provides an idempotency mechanism. If an API does not, but it is under your control, extend it accordingly. And if an API which is not under your control does not provide such a mechanism, it should at least have means to undo an operation and/or to validate whether an operation with a certain ID was already processed, so you can implement a retry or rollback mechanism around it by yourself. Commented Jan 8 at 5:53
  • 1
    ... and in case an API provides none of these things, find a better API ;-) Commented Jan 8 at 5:55
  • 1
    @del: for an API of a service which does a local operation, implementing reliable idempotency for operations is pretty standard (maybe by utilizing means of a local DB, a file system with transaction logs etc). The hard part is to make this work in a distributed system - and this is what the Saga pattern is for, or the outbox pattern. Commented Jan 8 at 6:36
  • 3
    Depending upon how infrequently something actually fails in production, there are sometimes cases where the most reliable, pragmatic, low-risk and cost-effective way of working around failures from a bad API is just not to do anything and fall back to human support intervention instead -- remember that software engineering also involves making pragmatic business decisions, which includes balancing the realistic time/cost of a human solution versus a potentially difficult/expensive/complex computerised one -- even if you do automate it in the end, I would at least look into the human approach. Commented Jan 8 at 8:26
  • 1
    Note that practically, the payment provider will offer fault tolerance, e.g. by allowing you to check whether you already did a transaction (if they don’t, get a different provider ASAP). This technically just pushes the problem somewhere else (because payment providers also don’t do magic), but at least allows you to claim you made a reasonable effort. However, the way the question is asked this didn’t seem like a viable answer. Commented Jan 8 at 13:05