I recently just started learning about DynamoDB single table design. Now, I am trying to model Shipment Update data that has the following properties:
- an account has multiple users
- an account has multiple shipments
- a shipment can change eta multiple times
- each time there's a shipment update, a new record will be inserted
Access patterns:
- get all shipments of an account displaying the last updated status ordered by eta in an ascending order
- for a given shipment, get the chronological updates
I am having a difficulty trying to resolve the 2 access patterns mentioned above. If, per se, I only have 1 record per shipment, then I can just update the sort key for the shipment update items to be shpm#55abc
and the retrieval of all shipments for a given account by eta is straight forward, which is via the gsi accountEta
.
How do I resolve this to get the access patterns I need? Should I consider having a separate table for the shipment update audit, i.e. to store just the shipment updates? So that when I need access pattern #2, then I query this audit table by the shipment id to get all the chronological updates. But, I feel like this defeats the purpose of the single table design.