DynamoDB中的查找表设计

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

Lookup table design in DynamoDB

问题

我正在尝试在DynamoDB中设计一个简单的配置查找表。我想要存储三个类别的数据 - "下拉菜单"、"指标"和"字段"。

每个类别下可能有多个条目,例如100个下拉菜单、50个指标和200个字段。

我希望进行以下操作:

  1. 获取所有下拉菜单或指标或字段的配置,但不是同时获取所有配置。
  2. 能够只获取以特定前缀开头的下拉菜单/指标/字段。

我考虑以下设计:

分区键:类别(DROPDOWN/METRIC/FIELD)
排序键:类型-ID

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

这个设计允许我按照所需的类别获取所有配置。而且我还可以通过在排序键上使用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.html
匿名

发表评论

匿名网友

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

确定