Skill 1.3.4

Configure DynamoDB to support applications (for example, by selecting high-cardinality partition keys, applying read consistency models, performing query and scan operations, by defining keys, attributes, and indexes).

Key Concepts

Good partition keys include user IDs, order IDs or device IDs, where requests are spread across many values. Poor keys include a status field, a date or a small set of categories, where most traffic lands on a few values and overloads their partitions, causing throttling even though the table as a whole has spare capacity.

When the natural key is not distributed enough, you can add a random or calculated suffix (write sharding), for example 2026-10-05#7, and read across all suffixes when querying. DynamoDB's adaptive capacity helps with uneven traffic, but it does not replace a good key design.

DynamoDB reads are eventually consistent by default and may briefly return stale data after a write; they use half the read capacity of strongly consistent reads. Setting ConsistentRead=true on GetItem, Query or Scan returns the latest data. Strongly consistent reads are not available on global secondary indexes or across Regions in global tables.

Amazon S3 now provides strong read-after-write consistency for all operations. In relational databases, reads from the primary are consistent, while read replicas in RDS and Aurora replicate asynchronously and can lag behind.

A Query requires a partition key value and can add a sort key condition such as begins_with or BETWEEN. It reads only the items in that partition, so it is fast and cheap. A Scan examines every item in the table or index and consumes capacity for all of them, which becomes slow and expensive as the table grows.

Both return at most 1 MB per call and paginate with LastEvaluatedKey. A FilterExpression reduces what is returned but not what is read or paid for. If you need to scan, a parallel scan with several segments finishes faster, and a smaller page size (Limit) reduces the impact on production traffic.

A simple primary key is just a partition key. A composite primary key adds a sort key, so many items can share a partition key and be stored in sort-key order, which enables range queries such as all orders for a customer in a date range.

A local secondary index uses the same partition key with a different sort key, must be defined when the table is created, supports strongly consistent reads and limits each partition key's data to 10 GB. A global secondary index can use entirely different keys, can be added or removed at any time, has its own throughput and is eventually consistent. Each index chooses which attributes to project: keys only, selected attributes or all attributes.