You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Data modelling in DynamoDB is fundamentally different from relational databases. Instead of normalising data and using joins, you denormalise and design your table around your access patterns. This lesson covers the key modelling strategies.
In a relational database, you design the schema first and then write queries. In DynamoDB, you reverse the process:
| Model | Design Direction |
|---|---|
| Relational | Schema → Queries |
| DynamoDB | Access Patterns → Key Design → Schema |
Single-table design is the most powerful DynamoDB modelling technique. Instead of creating separate tables for each entity, you store all entities in a single table using structured partition and sort keys.
| Benefit | Description |
|---|---|
| Fewer round trips | Fetch related data in a single Query |
| Simpler operations | One table to manage, backup, and monitor |
| Transaction scope | Transactions work across items in the same table |
| Reduced costs | Fewer tables, fewer indexes |
Access patterns:
| PK | SK | Attributes |
|---|---|---|
| CUST#c001 | PROFILE | { Name: "Alice", Email: "alice@..." } |
| CUST#c001 | ORDER#o001 | { Date: "2024-01-15", Total: 49.99 } |
| CUST#c001 | ORDER#o002 | { Date: "2024-02-20", Total: 29.99 } |
| ORDER#o001 | ITEM#i001 | { Product: "Widget", Qty: 2, Price: 19.99 } |
| ORDER#o001 | ITEM#i002 | { Product: "Gadget", Qty: 1, Price: 10.01 } |
| ORDER#o002 | ITEM#i003 | { Product: "Gizmo", Qty: 3, Price: 9.99 } |
Queries:
PK = "CUST#c001" AND SK = "PROFILE"PK = "CUST#c001" AND SK begins_with "ORDER#"PK = "ORDER#o001" AND SK begins_with "ITEM#"PK = "CUST#c001"The adjacency list pattern models many-to-many relationships in a single table:
| PK | SK | Attributes |
|---|---|---|
| USER#alice | PROFILE | { Name: "Alice" } |
| USER#alice | GROUP#runners | { JoinedAt: "2024-01" } |
| USER#alice | GROUP#readers | { JoinedAt: "2024-02" } |
| USER#bob | PROFILE | { Name: "Bob" } |
| USER#bob | GROUP#runners | { JoinedAt: "2024-03" } |
| GROUP#runners | MEMBER#alice | { Role: "admin" } |
| GROUP#runners | MEMBER#bob | { Role: "member" } |
| GROUP#readers | MEMBER#alice | { Role: "member" } |
Queries:
PK = "USER#alice" AND SK begins_with "GROUP#"PK = "GROUP#runners" AND SK begins_with "MEMBER#"PK = "USER#alice" AND SK = "PROFILE"Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.