Rutagon builds a consumer that posts a payment event once, for a company whose queue delivers the same event twice and whose customers see two charges. The deliverable is an idempotent payment event consumer on AWS: the event id is stored before the charge call, and a duplicate delivery returns the first result. The named outcome is the duplicate charge that does not happen.
Idempotent payment event consumer on AWS
The failure this removes is a second charge for one payment event. Queues deliver more than once. A function that charges and then writes "done" will charge again when the first attempt times out after the processor accepted it. Idempotent payment event consumer on AWS reverses that order. The consumer writes the event id under a condition that fails if the id is already present, and only the writer that wins the condition calls the processor. AWS documents the condition on the DynamoDB write. The duplicate sees the existing row and stops.
We do not rebuild your checkout, and we do not choose a new payment processor. The consumer is the door in front of the charge you already make. A Lambda and DynamoDB API is the neighboring shape when the workload is a request API rather than a payment event. Duplicate payments stopped is the finance-side match when the same bill is about to be paid from the ledger. This build is the event consumer. Full-stack development is the lane, on the account in AWS cloud infrastructure.
event_id, charge_state, charger_ref
Charge_state starts as started, and it becomes posted only with the processor reference. If the process dies after started and before posted, a person sees that row. We do not automatically charge it again, and we do not automatically mark it posted. The dangerous case is the one the condition already covers: a second delivery when posted is set. That delivery does not call the processor. The ambiguous case stays ambiguous until a person matches the processor's own record. A model does not decide that a charge happened.
The event id is the id the producer already puts on the payment, not a random id the consumer mints per delivery. A random id would make every retry look new. If the producer does not send a stable id, we stop and the producer gets that requirement. We do not hash the whole body and hope a changed field still means the same payment. The fields that define "same payment" are written on the first page: the id, and any field that must match or the row is a different event. A changed amount with the same id is an exception, not a second charge and not a silent overwrite.
The meter is two counts you can re-pull: events delivered, and charge calls made. For a replay of the same ids, delivered goes up and charge calls do not. That gap is the result. We do not describe a percentage of "duplicates avoided" from a guess. The test is a replay of a posted event id against a non-production processor key, or against a stub that records the call, in the account you approve. A production replay of a live charge is not the test. On a production SaaS platform the same condition sat in front of the charge: one id, one processor reference, a replay that returned the reference and did not call again.
What you re-run is the table and the two counts. The note names the table and the queue. A new person should be able to look up an event id and see charge_state and the processor reference. We do not keep the only copy of that table. The role the consumer uses is one you can revoke. We do not leave a processor secret in a personal environment as the way the consumer was finished. The secret stays in the account, in a role the function assumes.
A refund, a capture after an authorization, and a payout are different events with different ids. We do not treat a refund as a duplicate of the charge because the customer id matches. The handoff lists the event types in population. An event type not on the list is not given this consumer. Mixing them is how a refund consumer skips a refund it thinks it already charged.
A second cycle that shows two processor references for one event id means a path called the processor outside the condition. We name that path. We do not add a cleanup job that refunds the second charge inside this build. The refund is a person, with the two references in front of them. The report is the table and the counts. A dashboard that hides the started-but-not-posted rows is not the delivery.
Book a technical call. 907-841-8407. contact@rutagon.com.
Frequently Asked Questions
What stops the second charge?
The event id is written with a condition before the processor is called. The delivery that loses the condition reads the existing row and returns it, and it does not call the processor. The id has to be the producer's stable payment id. An id minted per delivery would not dedupe anything.
What if the consumer dies after the charge and before the row says posted?
The row stays started, with no processor reference or with a reference we could not confirm. A person matches it to the processor. We do not automatically charge again, and we do not mark it posted to clear the queue. The duplicate case, where posted is already set, never reaches the processor.
Do you change the payment processor?
No. The consumer sits in front of the charge you already make. Checkout, refunds, and payouts stay out unless they are separate event types you put on the list. A refund is not treated as a duplicate of a charge because the customer matches, and each type has its own id.
How do you show the duplicate did not charge?
Two counts: events delivered, and charge calls made. A replay of posted ids increases the first and not the second. The test uses a non-production processor key or a stub, and we do not replay live charges to prove the point. You can look up one event id and see a single processor reference.