Separate delivery from business effect
Draw a timeline with receipt, durable effect, acknowledgment, and message removal. Failure between the effect and acknowledgment can leave the result completed and the message available for retry. Lambda’s SQS mapping processes at least once; the consumer must tolerate repetition.
In the fictional example, a reconciliation order was recorded but the function ended before acknowledging it. Reprocessing must not create another order. FIFO send deduplication has a five-minute window; it is not a transaction with an external payments service.
Define a stable identity for the business operation, retain its result, and decide how to handle an unknown external outcome. A timeout does not prove that an external operation failed. The runbook should support querying and reconciling before resending an order that may already have taken effect.
Handle the batch and protect ordering
By default, a batch failure can return messages already processed. With ReportBatchItemFailures configured and a valid response, the handler identifies individual failures. An uncaught exception still represents failure of the entire batch.
In a FIFO exercise, orders F-21, F-22, and F-23 belong to one group. F-21 completed; F-22 failed; F-23 has not been processed. Stop that path and return F-22 and F-23 as failed and unprocessed respectively.
Do not declare F-23 completed to free the queue. A group should match the domain requiring order, such as a portfolio. Putting all portfolios in one group can serialize independent work; using a random group per message can destroy required within-portfolio order. Document the choice against business requirements.
Available time and downstream pressure
For Lambda with a standard queue and batch window, inspected guidance recommends visibility timeout of at least six times the function timeout plus the window. With 35 seconds and a five-second window, the reference is 215 seconds. This is operational guidance, not a completion promise or the minimum service-validated bound; function timeout cannot exceed visibility.
For custom consumers, extending visibility should follow real progress. Align concurrency with downstream capacity. In FIFO with three active groups and a maximum of eight, the group limit bounds concurrent invocations at three before other limits apply.
For mappings without provisioned mode, sum maxima for queues sharing one function and compare with reserved concurrency. Adding consumers without assessing the database may merely increase timeouts and retries.
Recover without erasing failure evidence
A DLQ isolates messages needing analysis; it does not repair the payload or confirm the business effect. Retain reason, identity, attempts, and redrive authorization. In FIFO, moving a message to the DLQ can let later messages advance, breaking the operation sequence expected by the application.
The owner must decide how to pause or reconcile that group. For a standard queue, DLQ expiry still depends on the original enqueue time. If DLQ retention is 72 hours and the message is already 30 hours old, approximately 42 remain, assuming no further change.
Do not confuse age since DLQ entry with total age. At handover, combine backlog, in-flight work, isolated messages, and reconciled outcomes. Completion means an observed business result, not merely an empty main queue.
Resolve an unknown outcome before the dependent operation
Consider three ordered operations: prepare, charge and issue the receipt. Losing the charge response leaves at least two possible states: the recipient did not charge, or charged but its response did not arrive. Issuing the receipt or charging under a new key selects a state without evidence.
Recovery queries the original identity’s result or repeats the request under the recipient’s idempotency contract. Retain the payload to detect changes under the same key. Confirmation permits progress; an unresolved outcome keeps that operation and its dependent operation pending.
The replay horizon must fit within identity retention. The partial list contains failed and unprocessed message IDs, whereas the business key identifies the charge: these are different identities. Acceptance checks should lose the response after the effect and demonstrate that recovery returns the same result without another debit.
Choose idempotency identity and retention
Build a matrix before choosing a key: the same purchase on a new attempt must match; distinct purchases, even with equal payloads, must differ. A per-attempt UUID fails the first condition and a payload hash can fail the second. At the consumer, writing the marker before the effect can lose the effect after a crash; writing the effect first can duplicate it before the marker.
A local transaction can couple both when they share transactional storage. External effects require another explicit contract. Add the time dimension: an order resent two days later is still the same operation.
Define the replay bound, permitted delays and retention headroom, and reject requests outside the contract. Changing payload under one identity must cause a conflict or investigation, not silent acceptance.
Calculate the shared worst case across sources
The maxima of two sources are not independent reservations. Express limits as variables: a and b are permitted concurrent invocations. In the model, a+b≤15 protects the function reservation and a+3b≤24 protects database connections.
Add a≥6 and b≥4 to preserve required capacity for the trial. The combination 9/5 fits: sum 14 and consumption 24. The combination 10/5 passes the first inequality but fails the second.
The combination 5/6 passes the ceilings but fails A’s minimum. These are configuration bounds; they do not establish immediate invocation starts or compliance with business latency. Connection reuse, parallel tasks per invocation and other sources require revisiting the consumption model before applying these numbers to an environment.
Original FIFO worksheet; not a deployable handler
Group = portfolio-17
F-21: durable completion
F-22: processing failure
F-23: unprocessed
ReportBatchItemFailures enabled
Return failures: F-22, F-23
Do not execute F-23 ahead of unresolved F-22Order R-804 has an unknown external result after a timeout. APS preserves identity and queries the outcome before authorizing another attempt.
Common pitfalls
Confusing FIFO with external atomicity; returning success for unfinished work; increasing concurrency against a saturated dependency; treating the DLQ as resolved storage.
Related topics: Consistency, transactions, and Regions
Retries must preserve the business outcome; ordering, time, and recovery need explicit decisions.
References
- Using Lambda with Amazon SQS · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- Handling errors for SQS in Lambda · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- SQS visibility timeout · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- Configuring an SQS event source mapping · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- Scaling SQS event source mappings · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- FIFO deduplication · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- SQS message group IDs · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- Using SQS dead-letter queues · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- SAP-C02 domain 2 tasks · AWS documentation inspected 2026-10-05; SAP-C02 task mapping
- Making retries safe with idempotent APIs · AWS Builders Library inspected 2026-10-05