04 / 04

How does Lambda handle failures and retries?

AWS Lambda provides built-in mechanisms to handle function failures and automatically retry invocations depending on the type of trigger. These mechanisms help ensure resilience and reliability in event-driven applications by reducing the chances of data loss or missed executions.

Retry Behavior by Trigger Type
  1. 1

    Synchronous invocations (e.g., API Gateway): Errors are returned immediately to the caller. No automatic retry.

  2. 2

    Asynchronous invocations (e.g., S3, EventBridge): Lambda retries the function twice (for a total of 3 attempts), with delays between attempts.

  3. 3

    Stream-based triggers (e.g., DynamoDB Streams, Kinesis): Failed records are retried until they succeed or expire (up to 7 days).

Error Handling Options
  1. 1

    Use Dead Letter Queues (DLQs) to capture failed asynchronous events

  2. 2

    Enable Lambda Destinations for success/failure callbacks

  3. 3

    Use try/catch blocks and logging in your handler function

  4. 4

    Monitor CloudWatch Logs and metrics for error tracking

Sample DLQ Configuration (AWS CLI)
Difficulty: 5/10
Topics: async invocation, dead letter queues, idempotency

Scenario Questions

0-2 years experience
  1. 1

    You have a Lambda triggered by an S3 upload that calls a third-party API. The API times out once. What does Lambda do next, and what should your code do to be safe?

  2. 2

    A teammate asks why their SQS-triggered Lambda keeps processing the same message over and over. Walk them through what's happening and one code change to fix it.

2-5 years experience
  1. 1

    Your async Lambda (invoked via EventBridge) starts failing intermittently due to a flaky downstream service. You see a spike in retries and the DLQ filling up. How do you tune the retry behavior without losing events, and what's the tradeoff of each knob?

  2. 2

    You're debugging a Kinesis consumer Lambda where shard iterators are getting stuck. The logs show 'ThrottlingException' but concurrency isn't maxed. What's likely happening with retries, and how do you fix the backpressure?

5-8 years experience
  1. 1

    Design a retry strategy for a payment-processing Lambda that must never double-charge. The function calls Stripe, then writes to DynamoDB. Where do you put idempotency keys, how do you handle partial failures, and what DLQ/Destination config ensures auditability?

  2. 2

    Your team's Lambda fleet processes 50K events/min from SQS. A bad deploy introduces a bug that crashes on 5% of payloads. The retry storm takes down the downstream DB. How do you implement circuit-breaking at the Lambda level without AWS Step Functions?

8+ years experience
  1. 1

    You're migrating a legacy monolith to event-driven Lambdas. The old system had at-least-once delivery with manual deduplication. How do you architect the new retry/DLQ contracts across teams so downstream consumers can safely migrate without coordinated deploys?

  2. 2

    A critical Lambda has a 0.1% poison-pill rate that blocks shards for hours. You can't fix the payloads upstream. Propose a multi-layer handling strategy (code, config, observability) that isolates bad records, preserves ordering for good ones, and gives on-call actionable alerts — without increasing latency for the 99.9%.

Follow-up Questions

  • What happens if your function throws an error but the downstream service already processed the request?
  • How would you debug a case where retries are causing a thundering herd on a downstream API?