Retries, idempotence and deployment aliases
Retries depend on the invocation source
A synchronous client decides whether to retry a function error; some calling services have their own rules. For ordinary asynchronous Lambda invocation, function errors are retried twice by default, while throttling and service errors have different queue-based retry behavior. Configure maximum event age and retry attempts as appropriate. For event source mappings, source-specific rules determine when records are retried or removed; a batch can be delivered again. Do not apply the asynchronous retry count to SQS or stream processing.
Idempotence: one business effect
Imagine order o-101 requests two books. A handler records the order, then loses its response. A retry of the same event must not deduct two more books. Use a stable business operation key and a durable conditional write or transaction that records the effect and the key together. A repeated key with different content must be treated as a conflict, not silently accepted. A memory set inside a Lambda process cannot coordinate separate environments or survive replacement. For external side effects use the target service’s idempotency contract or an outbox and reconciliation strategy; a local flag alone cannot guarantee exactly-once behavior.
Observe failure and recover deliberately
An asynchronous dead-letter queue can retain discarded event payloads; a failure destination can receive an invocation record with additional context. These configurations need permission and monitoring; delivery to them may itself fail. Review failed records, redact sensitive data, repair the cause and replay only an authorized bounded set after confirming idempotence. For queue-triggered functions, use source-specific redrive and partial-batch response rules instead. Avoid event loops such as writing to the same S3 prefix that triggers the function.
Versioned deployments and aliases
$LATEST is the mutable working version. Publishing a numbered function version freezes code and most configuration. An alias such as prod is a named pointer to a published version and can route a configured fraction of requests to another compatible version. Example: version 7 is stable; version 8 receives 10% of traffic for a canary test. The actual fraction in a small sample can differ. Observe errors and latency, then shift traffic or restore the alias to version 7. Rollback does not undo database writes, external effects or incompatible schema changes; plan backward compatibility and reconciliation separately.
Practice: duplicate orders
Start with five books. Process o-101 for two, then repeat it, then process o-102 for one. The final stock should be two, not zero. Reject a replay of o-101 with a different quantity, and reject insufficient stock without recording success. The companion lab uses SQLite transactions locally to illustrate atomicity; it is not a DynamoDB, Lambda or distributed concurrency test. No actual order or AWS action occurs.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Retries, idempotence and deployment aliases — knowledge check
Reason about fictional Lambda workloads without an AWS account.
A write succeeded but the response was lost. What is the safest retry design?
Ordinary async function errors have what default additional retry count?
An existing operation key arrives with a different quantity. What should happen?
What can moving prod from version 8 back to 7 undo?
Which option can receive additional invocation context for failed asynchronous events?