gpt4 book ai didi

database - 如何在没有热分区的情况下使用 Amazon DynamoDB 为论坛建模?

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:58 24 4
gpt4 key购买 nike

AWS DynamoDB 文档包含一个示例 schema for a forum .然而,这个模式能够回答的问题数量似乎很少。此外,该表似乎存在热键问题(大量回复备份在同一分区上)。

在题为“Amazon DynamoDB 的高级设计模式”的演讲中,主持人 around 43 minutes breaks down来自 Audible 的复杂用例,仅使用具有 3 个 GSI(索引)的单个表。

我正尝试从标准 RDBMS 3NF 背景中学习正确的 DynamoDB 建模。如何设计论坛以防止热分区,同时仍然满足这些常见用例?

查询:

  • 按论坛划分的主题(按发布日期或最新回复排序)
  • 按主题回复(按发布日期分页排序)
  • 用户回复(按发布日期排序)
  • 用户主题(按发布日期排序)
  • 得票最多的主题

基本架构(?):

  • Forum: Partition key: Forum_GUID. Attributes: Name, Desc
  • User: Partition key: User_GUID. Attributes: email, join_date
  • Thread: Composite key: Forum_GUID, Topic_GUID. Attributes: posted_by, date, votes, body, subject
  • Reply: Composite key: Topic_GUID, Reply_GUID. Attributes: posted_by, date, votes, body

我假设有多种解决方案(包括使用单个表)。我正在寻找任何可以解决此问题的答案,同时提供有关何时以及如何解决 properly use indexes 的指导。扩展应用程序的写入。

最佳答案

enter image description here

您可以使用上述模式。现在为您查询

  1. 按论坛主题(按发布日期或最近回复排序)

     Select from GSI1 where GSI1 pk=Forum123 and sortby GSI1 SK

    您可以根据经常询问的用例选择将谁保留在 GSI1 Sk 最近的回复/发布日期中。

  2. 按主题回复(按发布日期分页排序)

     Select where pk=topic and sk startswith reply and sortby sk
  3. 用户回复(按发布日期排序)

     Select from GSI2 where pk=User123 and sk startswith reply and sortby sk
  4. 按用户分类的主题(按发布日期排序)

     Select from GSI2 where pk=User123 and sk startswith topic and sortby sk
  5. 得票最多的主题

This will require another GSI if you want to do this operation across multiple forums. but This GSI will certainly suffer from hot key issue. since there will be only one key. Instead of doing that, you can keep one fixed key value in your table who keeps these counts. and these values are updated by an async process.

关于database - 如何在没有热分区的情况下使用 Amazon DynamoDB 为论坛建模?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55340000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com