DVA-C02 - Development with AWS Services - Section 1.7

Model data in Amazon DynamoDB using primary keys, high-cardinality partition keys and secondary indexes, and choose between query and scan operations.

Design Amazon DynamoDB table schemas using partition keys with high cardinality to distribute load evenly, and define global secondary indexes to support access patterns not served by the base table. Choose Query over Scan whenever possible and understand the cost and consistency implications of each.

Partition keyGlobal secondary indexQuery versus ScanDynamoDB data modelling

Practice question for this objective

Free sampleDevelopment with AWS Serviceshard

A developer stores IoT sensor readings in a DynamoDB table. The primary access pattern is to retrieve every reading for one sensor within a given time range, ordered by timestamp. Each sensor produces thousands of readings per day across millions of sensors. How should the developer model the table's primary key?

  • AUse the timestamp as the partition key and the sensorId as the sort key so readings sort by time within each second.
  • BUse a single fixed string as the partition key and the sensorId as the sort key so all items share one partition for fast Query.
  • CUse a random GUID as the partition key and store sensorId and timestamp as plain non-key attributes for later filtering.
  • DUse the sensorId as the partition key and the timestamp as the sort key so each sensor's readings are stored together and sortable. Correct
Choose a high-cardinality partition key with a sort key that matches the dominant range query access pattern. DynamoDB distributes items by a hash of the partition key, so a high-cardinality value such as sensorId spreads load and avoids hot partitions, while a sort key on timestamp makes a single Query return an ordered contiguous range for one sensor.

Why A is wrong: A timestamp partition key spreads one sensor's readings across many partitions, so a single Query cannot return one sensor's range efficiently and creates hot partitions at write time.

Why B is wrong: A single fixed partition key concentrates every write and read on one partition, which throttles badly and defeats DynamoDB's horizontal scaling under high request volume.

Why C is wrong: A random GUID partition key spreads writes well but makes the required per-sensor time-range read impossible without a costly full Scan and filter expression.

Why D is correct: A high-cardinality sensorId partition key spreads load evenly, and the timestamp sort key lets one Query return a contiguous time range for a single sensor in order.

See more DVA-C02 practice questions, answers explained.

More in this domain

Back to all Development with AWS Services objectives, or the DVA-C02 cert hub.

Examworthy is not affiliated with or endorsed by Amazon Web Services. Original, blueprint-aligned practice material only.