Problem Statement
Outline how you would build an idempotent consumer for payment events.
Explanation
Define a stable idempotency key per payment attempt (e.g., gateway id). Before side effects, check a 'processed' table keyed by that id. If present, return the stored result; otherwise, perform the operation and record the outcome in the same transaction.
Make handlers resilient to retries and out-of-order messages. Keep compensations for partial failures and expose metrics for duplicates, lag, and failure reasons.
Code Solution
SolutionRead Only
BEGIN; if exists(processed,key) return; doWork(); insert(processed,key); COMMIT;
Practice Sets
This question appears in the following practice sets:
