I am not sure if this is correct place to ask this question.
I am new to dynamodb and trying to figure my way out to create a small web application. I've read the best practices here http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/BestPractices.html
My tables will be:
My approach currently to design the schema looks like this:
// 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
}
In order to list out all deliveries along with recipient details, I will be needing recipient details by recipient Id. That, according to the LSI docs, will mean making recipient Id as a sort key in the in the Building table.
Since you can only have top-level elements of the table (recipient not being the one), this seems impossible as per guideline https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GSI.html
The index key attributes can consist of any top-level String, Number, or Binary attributes from the base table; other scalar types, document types, and set types are not allowed.
So, I am hopeless this can be achieved without making another table, where I should copy all the recipients, updating them everything update happens in the table. Is there any other alternative or better approach?
Since a deliveries seems one to one relation of couriers with the recipient, is it okay to keep the ids and to iterate over all the recipient and couriers it at the time of listing all the deliveries?
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:
There are a lot of other solutions, if you expand your view and use more than one resource in conjunction.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.