Partition Key
In DynamoDB, a partition key is a primary key that determines the partition in which the item will be stored. A partition is a physical location where the data is stored, and each partition can handle a limited amount of read and write capacity. By using a partition key, DynamoDB can distribute items evenly across multiple partitions to support high levels of read and write throughput.
When you create a table in DynamoDB, you must specify the partition key. The partition key is used to uniquely identify each item in the table, and it also determines how data is distributed across partitions.
For example, let’s say you have a table that stores information about customers, and you choose the customer’s email address as the partition key. When a new customer is added to the table, DynamoDB will use the email address to determine which partition the customer’s data should be stored in. If two customers have the same email address, they will be stored in the same partition.
When you perform a query or a scan operation, the partition key is used to identify which partition the requested data is stored in, and the query or scan is performed only on that partition. This allows DynamoDB to quickly retrieve the requested data without having to search through all the partitions in the table.
It’s also worth mentioning that DynamoDB allows for using a composite primary key, which is composed of a partition key and a sort key. The partition key is used to distribute the data across partitions, and the sort key is used to sort the data within a partition. This allows for more fine-grained querying and more efficient retrieval of specific subsets of data from the table.
It’s important to keep in mind that partition key value should be chosen in a way that it distributes the data evenly across the partitions, and partition key value should be unique for each item in the table.
How DynamoDB partition a record?
When an item is inserted into a table, DynamoDB uses the partition key value to calculate a hash value.
When you perform a query or a scan operation, DynamoDB uses the partition key value to determine which partition the requested data is stored in.
How to modify hash function?
It is not possible to modify the built-in hash function used by DynamoDB, but you can control the distribution of items in your table by choosing an appropriate partition key.
When you change the Provisioned Throughput for a table, DynamoDB will also automatically adjust the distribution of data across partitions to ensure that the table can handle the new level of read and write capacity.