DynamoDB中的查找表设计

huangapple go评论75阅读模式
英文:

Lookup table design in DynamoDB

问题

我正在尝试在DynamoDB中设计一个简单的配置查找表。我想要存储三个数据类别 - "dropdowns"、"metrics"和"fields"。

每个类别下会有多个条目,例如100个dropdowns、50个metrics和200个fields。

我需要以下操作:

  1. 获取所有dropdowns、metrics或fields的配置,但不是同时获取。
  2. 能够只获取以特定前缀开头的dropdowns/metrics/fields。

我考虑如下设计 -

分区键:category(DROPDOWN/METRIC/FIELD)
排序键:type-id

pk sk
DROPDOWN type1-1234
DROPDOWN type1-1235
DROPDOWN type2-1234
METRIC type1-123
FIELD type1-123

这个设计允许我按照所需的类别获取所有条目。而且,我还可以使用sk上的BEGINS_WITH运算符进一步按类别内的类型进行过滤。

然而,我了解到非均匀的分区键并不推荐,因为它可能导致热分区的问题。是否有人可以建议一个适用于我的用例的替代表格设计?

注意:要存储在表中的总记录数不大。(< ~10,000)

英文:

I'm trying to design a simple configuration lookup table in dynamodb. I want to store three categories of data - "dropdowns", "metrics" and "fields".

Each category would have mutiple entries under them for example 100 dropdowns, 50 metrics and 200 fields.

I want the following operations:

1. Get all dropdowns or metric or fields config. But not all at the same time.
2. Ability to get only dropdowns/metrics/fields starting with a prefix.

I'm thinking of below -

Partition key: category (DROPDOWN/METRIC/FIELD) 
Sort key: type-id
pk sk
DROPDOWN type1-1234
DROPDOWN type1-1235
DROPDOWN type2-1234
METRIC type1-123
FIELD type1-123

This design allows me to fetch all by the required category. And also I can further filter by type within a category by using BEGINS_WITH operator on the sk.

However, I understand having a non-uniform partition key is not recommended as it can lead to problems of hot partition.
Can someone suggest an alternative table design that works with my use case?

Note: Total records to store in the table is not big. (< ~10,000)

答案1

得分: 1

你的设计对你的需求来说很好。如果你需要每秒加载10,000个项目而不是总共加载10,000个项目,那就是你需要稍微考虑一下“热度”的时候。

英文:

Your design is fine for your needs.

If you had to load 10,000 items per second instead of 10,000 total, that's when you'd want to do a little extra thinking about "heat".

huangapple
  • 本文由 发表于 2023年8月9日 12:15:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864532-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定