Designing an Idempotent Payment API in ASP.NET Core
DEV Community
Designing an Idempotent Payment API in ASP.NET Core
In a recent project, we needed to prevent duplicate charges when clients retried requests after timeouts. The core issue was that the payment endpoint processed each POST without checking whether the same transaction had already been handled. I introduced an Idempotency-Key header, persisted each key with its response in a SQL Server table, and returned the stored result on subsequent calls. This required careful transaction handling to avoid race conditions and ensured that retries never produced extra charges. The takeaway is that idempotency is essential for any mutable operation exposed over HTTP.
0 comments
No comments yet.