Question 1 · choose 1
An Amazon DynamoDB table stores sensor readings from 40,000 devices. Its partition key is deviceType, which has four possible values, and its sort key is the reading timestamp. Writes are throttled even though the table uses far less than its total capacity. Every read asks for one device's readings in a time range. Which primary key design fixes the throttling and still serves the reads?
- APartition key set to the reading date, rounded to the day; sort key set to deviceId and timestamp
- BPartition key set to the reading's status, such as OK, WARN or ERROR; sort key set to the timestamp
- CKeep deviceType as the partition key and add a local secondary index on deviceId
- DPartition key set to deviceId; sort key set to the timestamp
Show the answer and why
APartition key set to the reading date, rounded to the day; sort key set to deviceId and timestamp
Incorrect
A creation date rounded to a day is a poor partition key: every write on a given day goes to the same key value.
BPartition key set to the reading's status, such as OK, WARN or ERROR; sort key set to the timestamp
Incorrect
A status code with only a few possible values concentrates traffic on a few keys, the same problem as deviceType.
CKeep deviceType as the partition key and add a local secondary index on deviceId
Incorrect
A local secondary index keeps the base table's partition key, so every write still lands on one of the four deviceType values.
DPartition key set to deviceId; sort key set to the timestamp
Correct
deviceId has many distinct values, so writes spread across partitions, and a Query on one deviceId with a timestamp range serves each read.
Choose a partition key with many distinct, evenly accessed values; low cardinality keys such as types, statuses or dates create hot partitions.
AWS documentation