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

标签 database amazon-web-services database-design nosql amazon-dynamodb

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/

相关文章:

database - 使用 interbase 设计数据库表的最佳方法?

typescript - 如何使用 AWS CDK 检查自定义 VPC 是否已存在?

amazon-web-services - AWS API 网关行为不一致。正在运行的 API 收到 403 错误

MySQL不查询就删除数据?

mysql - 回滚事务无法正常工作

SQL 聚合函数 : Sum of some rows in another row

amazon-web-services - elastic beanstalk将同一个分支部署到多个环境

sql - 两个表基于条件的关系

database - 如何在一个数据库字段中插入多个条目

数据库设计结构|产品与产品 child