Resilient code with the AWS SDKs
DVA-C03 · Lesson 2 of 24 · 11:00
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: SDK retries with exponential backoff and jitter, which errors to retry, idempotency keys, graceful degradation and circuit breakers, SDK calls, pagination, partial batch failures, serialization, and Retry and Catch in Step Functions. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Errors will happen
At AnyCompany Tickets, the order service calls DynamoDB, SQS, and a payment partner thousands of times a minute during sales. Some calls will be throttled, some will time out, and the partner will be down for a few minutes now and then. This lesson covers resilient code: retries with backoff, idempotency, graceful degradation, calls through the AWS SDKs, and serializing data for AWS services.
Retries with backoff
Retry only the errors that can succeed later: throttling, like a ThrottlingException, timeouts, and server errors in the 500 range. A validation error or an access denied error fails again on every attempt, so the code must not retry it. Each retry waits longer than the last, which is exponential backoff, and adds a random amount of time, called jitter, so that thousands of clients do not retry at the same instant. The AWS SDKs do this for you, in the standard retry mode, which is the default, with three attempts in total for most clients. And the adaptive mode adds client-side rate limiting, for a single resource that throttles a lot.
Idempotency
Retries mean that the same request can arrive twice, so a write must be idempotent: running it twice must give the same result as running it once. Many AWS APIs accept a client token for this, and your own APIs can accept an idempotency key, like the order ID. The service stores each key with a conditional write in DynamoDB, and returns the first result when the same key comes back. Without this, a retried payment call could charge a fan twice.
Graceful degradation
When a dependency is down, the application should degrade gracefully instead of failing as a whole. The seat map can show cached availability with a warning, and the recommendations panel can simply disappear, while ticket purchases keep working. A circuit breaker stops calling a failing service for a while, after too many timeouts, and returns a fallback at once, then tries again later. And every call needs a timeout, so a hanging dependency cannot hold every thread of the service.
Working with the SDKs
The AWS SDKs sign every request, retry for you, and turn responses into objects of your language. Large results come in pages, so the code must follow the continuation token, like NextToken, or LastEvaluatedKey in DynamoDB, or simply use the paginator of the SDK. Batch calls, like SendMessageBatch or BatchWriteItem, can partly fail, so the code must check for failed entries or unprocessed items, and send them again. Errors arrive as exceptions with an error code, which the code checks to choose between a retry and a failure. And in a workflow, a Step Functions task can declare its own retries, with an interval, a maximum number of attempts, and a backoff rate, then catch the error to run a fallback state.
Serialization
Serialization turns objects into text or bytes that a service can carry, and deserialization turns them back. Most AWS APIs carry JSON: an SQS message body is a string, so the code serializes an order to JSON before sending it, and parses it after receiving it. Some fields carry binary data as base64 text, like Kinesis records delivered to Lambda, or a binary response from API Gateway with the isBase64Encoded flag. And DynamoDB stores typed attributes, like strings, numbers, and maps, which the document clients of the SDKs convert from and to native objects.
Recap
Let's recap. Retry throttling, timeouts, and server errors, never validation or access errors. Retries use exponential backoff with jitter, and the SDKs do it for you in the standard mode. Idempotency keys and client tokens make repeated requests safe. Graceful degradation, circuit breakers, and timeouts keep the core of the application running. And code follows pages, checks partial batch failures, and serializes data as JSON or base64 text.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
During a sale, the order function writes to DynamoDB and sometimes receives a ProvisionedThroughputExceededException. Each time, the function fails the order at once. What should the developer do?
- Retry the write at once in a loop until it works
- Let the SDK retry with exponential backoff and jitter
- Catch the exception and return an error to the fan
- Retry every error the function receives, of any type
Show the answer
Let the SDK retry with exponential backoff and jitter
Throttling errors can succeed later, so the SDK's retries with exponential backoff and jitter should handle them, before the order fails. “Retry the write at once in a loop until it works” would retry at once, at the same instant as every other client, and make the throttling worse. “Catch the exception and return an error to the fan” would keep failing orders on the first throttle. And “Retry every error the function receives, of any type” would retry errors, like validation errors, that can never succeed.
A nightly job calls BatchWriteItem to load twenty-five sales records at a time, and the report shows a few records missing, although no exception was raised. What did the developer miss?
- A permission for BatchWriteItem in the job’s role
- A JSON format for the sales records in the request
- A smaller batch of records in each request
- A loop that sends the unprocessed items again
Show the answer
A loop that sends the unprocessed items again
BatchWriteItem can succeed while leaving some items unprocessed, so the code must send the unprocessed items again, with backoff. “A permission for BatchWriteItem in the job’s role” is wrong, because the SDK would have raised an exception for a missing permission. “A JSON format for the sales records in the request” would change the record format, not the partial failure. And “A smaller batch of records in each request” would only slow the job, and still drop the unprocessed items.
A Lambda function reads records from a Kinesis data stream and calls json.loads on the data field of each record, which fails every time. What should the developer do first?
- Decode the data from base64 before parsing
- Call json.dumps on the data field instead
- Lower the batch size of the event source
- Send the records as JSON from the producer
Show the answer
Decode the data from base64 before parsing
Lambda delivers each Kinesis record's data as base64 text, so the function must decode it before parsing the JSON. “Call json.dumps on the data field instead” would change nothing, because the data is still base64 text. “Lower the batch size of the event source” would only change how many records arrive at once. And “Send the records as JSON from the producer” would keep the producer's JSON, and the same base64 text on the consumer side.