How does the DynamoDB partition key work?

前端 未结 3 1191
天命终不由人
天命终不由人 2020-12-23 12:32

I\'m trying to understand how the partition created for DynamoDB tables.

According to this blog, \"All items with the same partition key are stored together\", so if

3条回答
  •  粉色の甜心
    2020-12-23 12:33

    Point of confusion:

    Other answers already have detailed explanation of how partitions are created by DynamoDB. So with out going into that details, let me explain the root cause of confusion while trying to understand the relationship between Partition Keys and Partitions in DynamoDB.

    • IMHO, naming the key as "Partition Key" is the cause of confusion. It should just be called Primary Key. By hearing Partition Key, our mind start relating each Partition Key to one Partition. One-to-one relationship. Which is not the case. As mentioned in the question itself, the key is an input for the "internal hash function". The output of the function is the actual reference to the partition.

    • Thus, for a table having 1000 user ids ( Partition Keys), DynamoDB need not have 1000 partitions. It may have 1/5/10 any numbers of partitions, that is decided by the throughout (capacity unit) setting you have mentioned.

    • Partitions may be increased when you increase the throughput setting.

    • The number of partitions can also be increased based on the increasing volume of your data. When the existing partitions can not handle it.

    • Hence, what we call Partition Key in DynamoDB is nothing but Primary Key representing unique item in the table (with the help of sort key, in case of composite key). It does not relate one-to-one to a partition (which is a storage allocation unit for table backed by SSD) directly. Actual key to a partition is obtained by passing this partition key to an internal has function.

    More details here.

提交回复
热议问题