Skip to Content

AWS Builder Labs: How Data is Stored and Retrieved in Amazon DynamoDB Partitions

Learn how Amazon DynamoDB partitions data based on the primary key structure. Discover the role of hash and range attributes in determining item storage and retrieval.

Table of Contents

Question

Which statement about Amazon DynamoDB partitions is true?

A. A developer writes a hash function to tell DynamoDB how to partition the items.
B. If a table has a composite primary key, DynamoDB will sort the items based on the sort key before selecting the partition for the item.
C. If a table has a simple primary key (partition key only), DynamoDB stores and retrieves each item based on its hash attribute.
D. DynamoDB stores data in partitions and chooses the partition based on the range attribute.

Answer

C. If a table has a simple primary key (partition key only), DynamoDB stores and retrieves each item based on its hash attribute.

Explanation

If a table has a simple primary key (partition key only), DynamoDB stores and retrieves each item based on its partition key value. The partition key of an item is also known as its hash attribute.

In Amazon DynamoDB, data is stored in partitions, which are allocation units of storage for a table. When a table has a simple primary key, consisting of only a partition key, DynamoDB uses the value of the partition key as input to an internal hash function. The output from the hash function determines the partition in which the item will be stored.

When an item is written to the table, DynamoDB calculates the hash value of the partition key to determine the partition where the item should be stored. Similarly, when an item needs to be retrieved, DynamoDB again calculates the hash value of the partition key to determine the partition that contains the item.

The other options are incorrect for the following reasons:

A. Developers do not write hash functions to determine partitioning. DynamoDB handles partitioning internally using its own hash function.

B. The presence of a sort key (range attribute) does not affect the initial partitioning of items. Partitioning is solely based on the partition key. The sort key is used for sorting items within a partition.

D. The range attribute (sort key) is not used for selecting the partition. It is used for sorting items within a partition after the partition has been determined by the hash attribute (partition key).

AWS Builder Labs EDBLDRv1EN-US assessment question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the AWS Builder Labs EDBLDRv1EN-US assessment and earn AWS Builder Labs EDBLDRv1EN-US badge.