StudyToCert

All certifications / Developer Associate / Lessons

AWS Certified Developer – Associate DVA-C02 · Domain 1: Development with AWS Services

Resilient code: retries with exponential backoff and jitter, idempotency, timeouts, handling partial failures and dead-letter queues

▶ Watch the overview video

Last reviewed October 6, 2026 · Leer en español

Explain it simpler

Things on a network fail for a moment all the time, like a phone call that drops. Resilient code handles that calmly. If a call fails because the other side is busy, wait a little and try again, and wait longer each time; that is backoff. Add a bit of random waiting, called jitter, so everyone does not redial at the same second. Make actions safe to repeat, which is idempotency: pressing an elevator button twice still calls one elevator. Give every call a time limit so you do not wait forever. And if one message keeps failing no matter what, set it aside in a special holding area called a dead-letter queue so a person can look at it later while everything else keeps moving.

At 2:14 a.m. your phone buzzes. Northgate Utilities' billing queue has stopped moving, and the payment provider's dashboard shows a wall of throttling errors. Your teammate Priya pulls up the logs: thousands of Lambda invocations retried the same call at exactly the same instant, every few milliseconds, and one malformed message has been failing and reappearing in the queue for hours. Worse, a handful of customers were charged twice when a retry succeeded after the first attempt had quietly gone through. By morning you need to explain three things to your manager: why retrying made it worse, why customers were double charged, and why one bad message could jam everything.

Distributed systems fail in small ways all the time. A request is throttled because a service is protecting itself, a network call times out, or a downstream service briefly returns an error while it scales. Resilient code expects this and responds in a measured way instead of crashing or making things worse. The AWS Certified Developer – Associate (DVA-C02) exam tests whether you know the standard techniques, which failure each one fixes, and the AWS features that implement them.

Retries are the first tool, but only for transient errors. Good candidates are throttling (ThrottlingException, ProvisionedThroughputExceededException, HTTP 429), HTTP 5xx server errors and network timeouts, because the same request may well succeed a moment later. Retrying a validation error, a malformed request or an AccessDenied just repeats the failure and wastes time, since nothing about the request has changed. Retrying immediately in a tight loop is actively harmful: every client hammers the struggling service at once, which keeps it overloaded.

Exponential backoff solves the tight-loop problem by waiting longer after each failed attempt, for example 100 milliseconds (ms), then 200 ms, 400 ms and 800 ms, up to a maximum delay and a maximum number of attempts. Jitter adds randomness to each wait. Without it, thousands of clients that failed at the same moment would all retry at the same moment, recreating the spike in synchronized waves. With jitter, their retries spread out over time and the service can recover. The AWS SDKs already implement retries with backoff and jitter for calls to AWS APIs; you configure the retry mode and maximum attempts rather than writing the loop yourself. For calls to your own services or third-party APIs, you add the same logic in your code or with a retry library.

Idempotency is what makes retries safe. An operation is idempotent if performing it twice has the same effect as performing it once. This matters because duplicates are normal in AWS: an SDK retry may resend a request that actually succeeded, SQS standard queues deliver messages at least once, and Lambda retries failed asynchronous invocations. Your code should detect and ignore repeats. Common techniques are an idempotency key supplied by the client, such as an order ID or payment ID; a DynamoDB conditional write such as attribute_not_exists(orderId) that fails with ConditionalCheckFailedException if the item was already processed; and natural idempotency, such as setting a status to SHIPPED rather than incrementing a counter.

Timeouts stop one slow dependency from consuming all your resources. Set explicit connect and read timeouts on HTTP and SDK clients, and make them shorter than your function or request timeout. That way your code gets control back in time to log the problem, retry or return a clean error, instead of being killed mid-operation with no useful log line. A Lambda function behind Amazon API Gateway, for instance, should give up on a slow downstream call well before API Gateway's own integration timeout, so the client gets a meaningful response rather than a generic gateway error.

Partial failure happens when a batch contains good and bad items. If one record in a batch of ten fails and your code throws an error for the whole batch, the entire batch is retried, including the nine that already succeeded, which wastes work and can create duplicates. Batch APIs report per-item results so you can avoid this: DynamoDB BatchWriteItem returns UnprocessedItems, and SQS SendMessageBatch returns a list of failed entries. Your code must retry only those, ideally with backoff. For Lambda functions that read from SQS, Kinesis or DynamoDB Streams, partial batch responses let you report just the failed items so Lambda retries only them.

A dead-letter queue (DLQ) is where messages go after they have failed a set number of times. Its job is to deal with a poison message, one that can never be processed successfully, perhaps because its JSON is malformed or it references a record that no longer exists. Without a DLQ, a poison message keeps returning, wasting compute and, in ordered systems, blocking everything behind it. In SQS you attach a redrive policy to the source queue with a maxReceiveCount; once a message has been received that many times without being deleted, SQS moves it to the DLQ. Asynchronous Lambda invocations can send failed events to an SQS queue or SNS topic configured as the function's DLQ, or to a richer on-failure destination.

A DLQ is only useful if someone notices it. Create an Amazon CloudWatch alarm on the DLQ's ApproximateNumberOfMessagesVisible metric, investigate what lands there, fix the cause, and then redrive the messages back to the source queue. Together these techniques form a pattern the exam returns to often: retry transient errors with backoff and jitter, make handlers idempotent, bound every call with a timeout, retry only failed batch items, and catch the leftovers in a monitored DLQ.

Think of it like this Think of a crowded coffee shop when the espresso machine jams. If every customer shouts their order again every second, the barista never recovers; that is retrying without backoff. If each customer waits a little longer each time, and some wait a few seconds more than others at random, the line recovers; that is backoff with jitter. Writing your name on the cup so a repeated order is not made twice is idempotency, and the counter where unclaimable cups go is the dead-letter queue. The analogy stops short in one way: a DLQ does not fix anything on its own, it only holds messages until you investigate.

Key terms

Exponential backoff
A retry strategy where the wait between attempts grows multiplicatively, reducing pressure on a struggling service.
Jitter
Random variation added to retry delays so many clients do not retry in synchronized waves.
Idempotency
The property that repeating an operation produces the same result as doing it once, making retries and duplicate deliveries safe.
Poison message
A message that fails processing every time it is received and would loop forever without a dead-letter queue.
Dead-letter queue (DLQ)
A queue that receives messages or events that failed processing after a configured number of attempts, for later inspection.
Idempotency key
A unique value, such as an order ID, sent with a request so the receiver can detect and ignore repeats of the same operation.
Redrive policy
The SQS setting that names a dead-letter queue and the maxReceiveCount after which failed messages move to it.
Real-world example

A payment Lambda function processes SQS messages. It records each payment ID in DynamoDB with a conditional put using attribute_not_exists, so a message delivered twice is charged once. Its SQS queue has a redrive policy with maxReceiveCount of 5 and a DLQ, and a CloudWatch alarm fires when the DLQ holds any messages.

Common mistakes

You decide

Corvid Logistics uses a Lambda function to process SQS messages that each create a shipping label through a partner API. Occasionally the partner API times out after creating the label, the message is retried, and the customer receives two labels. The team wants to keep automatic retries. What should the developer change?

Show the answer

Make the handler idempotent. Before calling the partner, record the message's shipment ID in DynamoDB with a conditional put using attribute_not_exists, and skip processing if the condition fails, or pass an idempotency key to the partner API if it supports one. Removing retries would lose real failures, so idempotency is the right fix.

Exam tip: If a question mentions throttling errors such as ProvisionedThroughputExceededException or ThrottlingException, the answer is almost always retries with exponential backoff (and jitter), not simply adding more retries or raising timeouts.

Check yourself

Why add jitter to exponential backoff?

Without randomness, clients that failed together retry together, recreating the load spike; jitter spreads retries out over time.

Which errors should not be retried?

Client errors that will fail again unchanged, such as validation errors, malformed requests or AccessDenied; retry only transient errors like throttling, 5xx and timeouts.

How does a DLQ help with a poison message in SQS?

After the message's receive count exceeds maxReceiveCount, SQS moves it to the DLQ, so it stops being retried and blocking processing, and you can inspect it.

A Lambda function processes a batch of ten SQS messages and one fails. How do you avoid reprocessing the nine successes?

Enable partial batch responses (ReportBatchItemFailures) and return only the failed message ID, so only that message is retried.

Study Developer Associate for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the Developer Associate study plan