0

I come from relational database background and I'm struggling with the concepts of a single table to represents all my data in DynamoDB.

My application has Manufacturers and they give access to their staff to my portal CRM (Manufacturer Users). The Users then add their own customers to the system and log and record all their orders.

  • GetManufacturer()
  • GetManufacturerUsers()
  • GetManufacturerCustomers()
  • GetManufacturerCustomersOrders()

A Manufacturer will never see another Manufacturers Customers orders.

I understand the basics around PK and SK, my question is... really? Is this really single table?

Table Customer Accounts

  • Manufacturers (Name, logo etc)
  • Manufacturer Users (Users of that Manufacturer that access my system i.e. email, role)
  • Customers of the Manufacturer (custID, Name Manufacturer they belong to)
  • Customer transaction data (lots of it)

Given the above, how would you model in DynamoDB?

Access pattern stories

  • Query Manufacturer (Login, Name) by Users SK ManufacturerID
  • Get all Customers IDs and Name by ManufacturerID Filter by UsersID
  • Get all Orders filtered by CustomersID and ManufacturerID
  • Get all Ordered Items filtered by OrdersID and CustomersID
MarkK
  • 968
  • 2
  • 14
  • 30
  • 1
    Is there a particular part of the data modeling process you are struggling with? You mention familiarity with PK/SK patterns, but don't state what you have already tried or where you are stuck. It appears you have several one-to-many relationships to model. There are several ways to model these types of relationships. Selecting the right ones will depend on the details of your access patterns (which we don't know) I'd suggest getting started with learning more about modeling one-to-many relationships. I'd start here: https://www.alexdebrie.com/posts/dynamodb-one-to-many/ – Seth Geoghegan Jan 26 '21 at 17:39
  • @SethGeoghegan Thank you, your comment is very helpful. I will try to answer your questions. I have updated the question with `Access pattern stories` to give you a better idea of the user stories I have. From a relational database viewpoint, I have no problem, with DynamoDB I started to design by creating a 'table' ManufacturerAndUsers PK which had Users SK. I created a second table, CustomersOrders. – MarkK Jan 27 '21 at 09:02

1 Answers1

1

As you're learning, NoSQL data modeling is completely different than data modeling in a SQL/relational database. Single table design requires you to think differently about your data, which can come with a steep learning curve.

Alex Debrie, author of The DynamoDB Book, has authored some of the best materials about data modeling in DynamoDB. His book is fantastic and I recommend it to anyone wanting to learn about NoSQL data modeling in DynamoDB.

In your situation, I'd start by reading an article on modeling one-to-many relationships in DynamoDB. You can also see the same material in this video presented at the 2019 AWS Re:Invet conference. Both of these resources will give you a much better understanding of single table design in DynamoDB. I haven't found a better resource that can jump-start the DynamoDB learning process.

Seth Geoghegan
  • 5,372
  • 2
  • 8
  • 23