Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

DynamoDB for developers

DVA-C03 · Lesson 9 of 24 · 1:09:05

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.

In this lesson

Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: partition and sort keys, hot partitions, Query and Scan, filters and projections, eventually and strongly consistent reads, global and local secondary indexes, capacity units, conditional writes, transactions, and throttling. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

A scan that grew

The first version of the order history page at AnyCompany Tickets scanned the whole orders table, then kept the orders of one customer. As the table grew, the page got slower and the bill got higher. This lesson covers DynamoDB from the developer's side: keys, Query and Scan, read consistency, secondary indexes, capacity, and safe writes.

Partition and sort keys

Every item has a primary key: a partition key alone, or a partition key and a sort key together. DynamoDB hashes the partition key to place the item on a partition, so a good key has many distinct values, used evenly. A key with few values, like a status or today's date, creates hot partitions that throttle, and a random suffix can spread those writes. Here, the partition key is the customer, and the sort key is the order date, so one request returns a customer's orders in date order.

Query, Scan, and consistency

A Query reads the items of one partition key, with an optional condition on the sort key, like a range of dates. A Scan reads every item in the table, one megabyte per page, and a filter expression only applies after the read, so it consumes the same capacity. For large exports, a parallel scan splits the table into segments, read at the same time. Reads are eventually consistent by default, and a strongly consistent read returns the latest write, for twice the cost. And a projection expression returns only the attributes that the app needs.

Secondary indexes

A global secondary index has its own partition key and sort key, so the app can query the data by another attribute, like the event of each order. You can add one at any time, up to twenty per table by default, and its reads are eventually consistent only. A local secondary index keeps the table's partition key with another sort key, it can serve strongly consistent reads, and it is only created with the table. Each index holds the attributes that you project into it, so include only what the queries need.

Capacity and throttling

One read capacity unit is one strongly consistent read per second of an item up to four kilobytes, or two eventually consistent reads. One write capacity unit is one write per second of an item up to one kilobyte. Sizes round up, so a three-kilobyte item takes one read unit, and a two and a half kilobyte item takes three write units. With on-demand mode, the table scales with traffic, and with provisioned mode, you set the units, with auto scaling. When a request goes over, DynamoDB throttles it with a ProvisionedThroughputExceededException, and the SDK retries it with backoff.

Safe writes

Two box offices can try to sell the same seat at the same moment. A condition expression makes the write succeed only if a condition holds, like no item yet for that seat, and otherwise DynamoDB rejects it with a ConditionalCheckFailedException. A version number checked in the condition gives optimistic locking for updates. And TransactWriteItems groups up to one hundred actions, across tables, in a single all-or-nothing operation, like a seat and its order.

Recap

Let's recap. A good partition key has many distinct values used evenly, and the sort key orders the items of each partition. A Query reads one partition, a Scan reads the whole table, and filters do not lower the capacity used. Reads are eventually consistent by default, and strongly consistent reads cost twice as much. Global secondary indexes add new access patterns at any time, while local ones are created with the table. And capacity units round up the item size, condition expressions protect writes, and transactions are all or nothing.

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.

  1. The orders table has the customer ID as its partition key, and the order date as its sort key. The history page must show one customer’s orders from the last thirty days. What should the developer use?

    • A Scan with a filter on customer and date
    • A BatchGetItem call with each order key
    • A strongly consistent Scan of the table
    • A Query with a key condition on the date
    Show the answer

    A Query with a key condition on the date

    A Query on the customer's partition key, with a condition on the order date, reads only the matching items. “A Scan with a filter on customer and date” would read the whole table, and the filter would not reduce the capacity used. “A BatchGetItem call with each order key” would need the key of each order in advance. And “A strongly consistent Scan of the table” would cost twice as much per read, and still read the whole table.

  2. A provisioned table stores items of three kilobytes. The app needs eighty strongly consistent reads per second. How many read capacity units does the table need?

    • 40
    • 80
    • 240
    • 160
    Show the answer

    80

    Three kilobytes round up to four, so each strongly consistent read takes one unit, and eighty reads need eighty units. “40” would be right for eventually consistent reads, which count two per unit. “240” would count each item as three units, as if it were measured per kilobyte. And “160” would double the units again, without any reason.

  3. The orders table uses the customer ID as its partition key. A new report must list all the orders for one event, and the table already holds millions of items. What should the developer add?

    • A local secondary index on the event ID
    • A Scan with a filter on the event ID
    • A global secondary index on the event ID
    • Strongly consistent reads on the table
    Show the answer

    A global secondary index on the event ID

    A global secondary index on the event ID lets the report query the orders of one event, and it can be added now. “A local secondary index on the event ID” would keep the customer as the partition key, and it can only be created with the table. “A Scan with a filter on the event ID” would read millions of items for each report. And “Strongly consistent reads on the table” would return fresher data, without a way to find the orders by event.