Step 5. Create the DynamoDB data model
Objective
-
Create the DynamoDB data model.
Process
-
Database engineer identifies how many tables will be required for each use case. We recommend maintaining as few tables as possible in a DynamoDB application.
-
Based on the most common access patterns, identify the primary key that can be one of two types: a primary key with a partition key that identifies data, or a primary key with a partition key and a sort key. A sort key is a secondary key for grouping and organizing data so it can be queried within a partition efficiently. You can use sort keys to define hierarchical relationships in your data that you can query at any level of the hierarchy (see blog post
). -
Partition key design
-
Define the partition key and evaluate its distribution.
-
Identify the need for write sharding to distribute workloads evenly.
-
-
Sort key design
-
Identify the sort key.
-
Identify the need for a composite sort key.
-
Identify the need for version control.
-
-
-
Based on the access patterns, identify the secondary indexes to satisfy the query requirements.
-
Identify the need for local secondary indexes (LSIs). These are indexes that have the same partition key as the base table, but a different sort key.
-
For tables with LSIs, there is a 10 GB size limit per partition key value. A table with LSIs can store any number of items, as long as the total size for any one partition key value does not exceed 10 GB.
-
-
Identify the need for global secondary indexes (GSIs). These are indexes that have a partition key and a sort key that can be different from those on the base table (see blog post
). -
Define the index projections. Consider projecting fewer attributes to minimize the size of items written to the index. In this step, you should determine whether you want to use the following:
-
-
Database engineer determines whether the data will include large items. If so, they design the solution by using compression or by storing data in Amazon Simple Storage Service (Amazon S3).
-
Database engineer determines whether time series data will be needed. If so, they use the time series design pattern to model the data.
-
Database engineer determines whether the ER model includes many-to-many relationships. If so, they use an adjacency list design pattern to model the data.
Tools and resources
-
NoSQL Workbench for Amazon DynamoDB — Provides data modeling, data visualization, and query development and testing features to help you design your DynamoDB database
-
NoSQL design for DynamoDB (DynamoDB documentation)
-
Choosing the Right DynamoDB Partition Key
(AWS Database blog) -
Best practices for using secondary indexes in DynamoDB (DynamoDB documentation)
-
How to design Amazon DynamoDB global secondary indexes
(AWS Database blog)
RACI
Business user | Business analyst | Solutions architect | Database engineer | Application developer | DevOps engineer |
---|---|---|---|---|---|
I |
I |
I |
R/A |
Outputs
-
DynamoDB table schema that satisfies your access patterns and requirements
Example
The following screenshot shows NoSQL Workbench.