One retry, two charges: a payment incident
A payment succeeds, the Lambda crashes before recording it, and a retry charges the same customer again. How should the system recover safely?
On this page
Illustrative scenario. This incident, timeline and numbers are invented for architecture practice. They are not from a client engagement or a payment platform I claim to have operated. The architecture below is a proposed design, not a deployed system.
What happened
An order for ₹12,000 is saved successfully. The payment provider charges the customer, but the Payment Lambda crashes before it can update Aurora. A second invocation receives the same payment event and submits another charge. The customer is now charged ₹24,000.
The business is processing 5 million orders a month. During a sales spike, traffic rises 8 to 10 times. In this illustrative incident, roughly 0.3% of orders have duplicate payment attempts. Aurora is healthy. The payment provider typically responds in 5 to 10 seconds, and its payment-status lookup can lag behind a successful charge.
| Time | What happened |
|---|---|
| 10:30:01 | Order ORD-9821 saved in Aurora. |
| 10:30:02 | Payment event published. |
| 10:30:05 | Provider successfully charges ₹12,000. |
| 10:30:06 | Payment Lambda fails before recording success. |
| 10:30:15 | A new invocation receives the event. |
| 10:30:17 | Another charge is submitted. |
Existing architecture
This is the simplified request path in the scenario. It shows the relevant components, not network boundaries, security controls or the complete production infrastructure.
Step 01
API Gateway
Receives the order request.
Step 02
Order Lambda
Writes the order.
Step 03
Aurora PostgreSQL
Stores the order state.
Step 04
EventBridge
Routes the payment event.
Step 05
Payment Lambda
Submits the charge.
- Step 06
Payment provider
Performs the external charge.
The failure is between an external side effect and an internal database update. The provider knows the charge succeeded. Aurora does not. A second worker cannot safely infer failure from the missing database record.
Constraints
- Keep order creation at a P99 target below 200 ms. Payment can remain asynchronous.
- Target 99.99% availability and handle traffic spikes of 8 to 10 times.
- Avoid duplicate charges for the same intended payment, even with concurrent workers.
- Do not silently lose accepted payment requests.
- Keep Aurora PostgreSQL and favor managed, serverless AWS components.
- Migrate without taking the order flow offline, and keep cost controlled.
- The provider has a status lookup API, but lookup results may be stale.
Missing requirement: the scenario does not say whether the provider accepts a durable idempotency key, how long it retains one, or whether support can reconcile an unknown charge. That contract affects what can actually be guaranteed.
Your challenge
You are responsible for this payment platform. How do you contain the incident, stop concurrent duplicate submissions, preserve payment requests and roll out a fix safely?
- What is the first action you take while customers are still being charged twice?
- What happens if the order commits but publishing to EventBridge fails?
- What happens when the provider charges successfully but the response or database update is lost?
- How will the design behave if two Lambda invocations start at the same time?
Make a decision before opening the walkthrough. In particular, decide whether an automatic retry is ever safe when the provider result is unknown.
Reveal the architect's walkthrough
The decision: keep accepting orders, but stop unsafe automatic payment resubmissions for ambiguous attempts. Build a durable payment intent in Aurora, publish through an outbox, and use one stable provider idempotency key per intended charge. This only supports safe automated retries when the provider's contract actually guarantees that key's behavior.
1. Scope
First, identify which payment attempts may have run twice. Correlate order ID, payment intent ID if it exists, provider reference, invocation ID and timestamps. Establish the affected period and the number of confirmed duplicate charges. A duplicate attempt is not automatically a duplicate charge.
Check whether the retry came from the EventBridge target path, Lambda's own asynchronous failure handling or application logic. Those are different controls and must not be treated as one retry system.
2. Investigate
Reconstruct three boundaries: Aurora commit to event publish, event delivery to payment execution, and payment submission to provider confirmation. Look at Lambda error logs and provider transaction records. A healthy Aurora instance does not prove that the application recorded a successful charge.
Confirm the provider's idempotency-key scope, retention period, request-matching rules and dispute or reconciliation process. Do not infer provider failure from an unsuccessful or stale status lookup.
3. Restore safely
Contain the unsafe retry path first. Keep new orders durable, queue affected payment intents for controlled reconciliation, and prevent a second charge while the first result is unknown. Identify customers already charged twice and follow the provider's supported refund and reconciliation workflow. Do not blindly replay the whole failed-event backlog.
A reversible feature flag or routing gate should coverevery active payment worker. Running old and new payment code at once is not safe if one version can bypass the payment guard.
4. Recommended architecture
Step 01
Order Lambda
Commits order and outbox event in one Aurora transaction.
Step 02
Aurora + outbox
Durable intent and event record.
Step 03
Outbox relay
Publishes unsent events and retries on delivery uncertainty.
Step 04
EventBridge
Routes the accepted payment intent.
Step 05
Payment worker
Claims a unique intent and handles uncertain outcomes.
- Step 06
Payment provider
Must honor a stable idempotency key for safe automated retries.
In one Aurora transaction, write the order and an outbox row. A small relay publishes pending rows to EventBridge. It checks the result for each PutEvents entry and marks only successful entries sent. An HTTP success alone is not sufficient: some entries can fail, and a missing event bus or matching rule can leave an apparently successful publish without processing. Validate the bus and rules during rollout. If the relay crashes after a successful publish but before marking the row sent, it may publish again. The payment worker must tolerate that duplicate.
Give each intended charge a durable payment_intent_id, a unique Aurora constraint and a stable provider idempotency key. This is not necessarily the order ID: a later authorized payment attempt, partial capture or separate charge may have its own identity. Claim a pending attempt with a conditional state transition before calling the provider. Keep the network call outside the database transaction.
Model explicit states such as PENDING, SUBMITTING, CONFIRMED, FAILED_FINAL and UNKNOWN. A timeout or lost response moves the attempt to UNKNOWN, not FAILED_FINAL. Reconcile UNKNOWN with the provider, allowing for delayed status visibility. If the provider guarantees idempotency for the same key and request, the worker can safely reuse that key according to the provider's documented limits. Otherwise, do not automatically submit another charge while the outcome is uncertain.
Use a dead-letter and recovery path for failed delivery, and inspect both EventBridge delivery failures and Lambda processing failures. They do not necessarily share the same retry or failure destination. Track the age of unprocessed outbox records and unknown payments, not just Lambda errors.
5. Trade-offs and failure modes
- Database guard only: prevents some concurrency, but cannot undo a charge when the worker crashes after the provider accepted it.
- Provider lookup only: a stale result can report no payment even though one succeeded. It cannot authorize a blind retry.
- Outbox: closes the order-write and event-publication gap, but adds relay work and still needs an idempotent consumer.
- Provider key: gives an external deduplication boundary only if its scope and lifetime cover the required recovery window.
- Fail closed on UNKNOWN: protects customer money but delays order completion and creates a reconciliation backlog.
If the provider cannot guarantee idempotent charge submission and reliable reconciliation, do not promise both automatic completion and zero duplicate charges under every network failure. That guarantee is impossible to establish from Aurora or EventBridge alone.
6. Verify
Test the exact crash points: before the provider call, after a successful charge, after a timeout, after an Aurora commit but before EventBridge publish, and with two simultaneous workers handling the same intent. Validate with provider transaction records rather than only application status.
Measure duplicate charges per intended payment, UNKNOWN age, reconciliation backlog, outbox publish lag, failed delivery, customer impact and order creation P99. At 10 times traffic, check Aurora connection usage, row contention, provider rate limits and relay throughput. No results are claimed here: these are acceptance tests for the proposed design.
7. Prevent and roll out
Introduce the schema and guard behind a feature flag, validate old payment records before adding constraints, then move every payment writer to the guarded path. Canary payment intents without issuing shadow charges. Ensure the rollback route cannot re-enable the old unsafe retry behavior. Assign one owner to UNKNOWN reconciliation and another to provider contract changes.
How I'd explain this in an interview
I'd first stop the retry path that can charge the same customer twice, but keep order creation running. Then I'd check the payment provider records and our Lambda logs to separate confirmed duplicate charges from attempts where the outcome is still unknown. I wouldn't retry an unknown payment just because Aurora wasn't updated, because the provider may have already taken the money. For the permanent fix, I'd store a unique payment intent in Aurora and use an outbox so saving an order can't leave its event behind. The payment worker would use a stable idempotency key with the provider, if the provider supports that contract. If it doesn't, I'd hold ambiguous payments for reconciliation instead of risking another charge. I'd test crashes at each handoff, concurrent invocations and 10 times traffic. Then I'd roll it out gradually and verify actual provider charges, the unknown-payment backlog and the order API latency before calling it fixed.
Sources
Pages were read on 2026-11-14.
AWS documentation
- Transactional outbox pattern: Why order persistence and event publication need a durable handoff; duplicate messages remain possible.
- Best practices for working with AWS Lambda functions: Idempotent processing, downstream throughput limits, timeouts and monitoring.
- What Amazon EventBridge logs for event buses: Target delivery retries and what happens when an event has no matching rule or delivery fails.
- Sending events with PutEvents in Amazon EventBridge: Per-entry publish failures and successful responses that do not prove a matching event bus or rule.
- Capturing records of Lambda asynchronous invocations: On-failure destinations for errors after an asynchronous invoke is accepted.
Next step
Have the same problem on your stack?
Send the architecture, AWS bill concern, deploy pain, or GenAI reliability issue. I'll find the first real bottleneck and propose a small, reversible fix.
Related reading

Rahul Ladumor
Principal Cloud & AI Platform Architect. AWS Professional certified, 5x AWS Community Builder. I work with teams that have real users, real AWS bills, and real production pressure.
About Rahul →