0

我不确定这是否是提出这个问题的正确地方。

我是 dynamodb 的新手,并试图找出创建小型 Web 应用程序的方法。我在这里阅读了最佳实践http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/BestPractices.html

我的桌子将是:

  1. 建筑物
  2. 租户(一栋建筑可以有尽可能多的租户,由楼层号标识)
  3. 收件人(每个楼层可以有多个收件人,基本上是租户的别名)
  4. 快递员
  5. 交付(与特定收件人绑定的快递员)

我目前设计架构的方法如下所示:

// Tables
// PK: Building Id, SK: name
- Building ID : {
  name: <Building Name>
  Tenants: [
     { TenantId: { Receipients: [{Receipient Id 1, Receipient Id 2...}] }
  ] 
}

// PK: Courier Id, SK: createdAt
- CourierId :  {
 name: <Courier name>
 ...
}

//PK: Not Sure, SK: Not Sure <-- This is where I messed up, looks relational, defeats the purpose?
- Deliveries: {
  receipient id: Courier id
}

为了列出所有交付以及收件人详细信息,我将需要按收件人 ID 列出的收件人详细信息。根据LSI文档,这意味着将收件人 ID 作为 Building 表中的排序键。

由于您只能拥有表格的顶级元素(收件人不是那个),因此根据指南https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GSI.html这似乎是不可能的

索引键属性可以由基表中的任何顶级字符串、数字或二进制属性组成;不允许使用其他标量类型、文档类型和集合类型。

因此,如果不制作另一个表,我应该复制所有收件人,更新他们所有更新都发生在表中,我希望这可以实现。还有其他替代或更好的方法吗?

由于交付似乎是快递员与收件人的一对一关系,因此在列出所有交付时是否可以保留 ID 并遍历所有收件人和快递员?

4

1 回答 1

0

Probably DynamoDB is not the best solution for your needs. As I understood, you have a relational data structure, mainly in the table related to deliveries. DynamoDB was designed to keep unstructured data, requested mainly by one or two keys. It was not designed to maintain relational integrity or provide table joins.

I don’t know if you have experience with cloud development, but using cloud infrastructure you can have one database per kind of data structure. For example:

  1. You can maintain your building and courier data in DynamoDB, and use it mainly requesting by ids; maybe even in the same table. You can have different documents/objects with different structure;
  2. You can save the deliveries information in a relational database using RDS. Depending on your AWS region you may try Aurora Serverless. It will cost you less.
  3. If your information in DynamoDB objects does not become big (DynamoDB objects/documents have a limit of 400 kB) you can save all the data in one object only and use a DynamoDB stream to sent the information to a search solution (CloudSearch or ElasticSearch). Than when you need to query a single delivery you use the search endpoint. When you need the building or tenant history you can use the DynamoDB endpoint.

There are a lot of other solutions, if you expand your view and use more than one resource in conjunction.

于 2018-10-04T22:20:45.197 回答