Make a New Year’s resolution: Follow Amazon DynamoDB best practices
As the new year begins, we encourage you to make a resolution to follow Amazon DynamoDB best practices. Following these best practices can help you maximize performance and minimize throughput costs when working with DynamoDB. Click the following links to learn more about each best practice in the DynamoDB documentation.
- Design and use partition keys effectively
The primary key that uniquely identifies each item in a DynamoDB table can be simple (a partition key only) or composite (a partition key combined with a sort key). Design your application for uniform activity across all logical partition keys in your table and its secondary indexes. You get the added benefits of burst capacity, adaptive capacity, and write sharding.
- Use sort keys to organize data
Well-designed sort keys gather related information together in one place where it can be queried efficiently. Composite sort keys let you define hierarchical (one-to-many) relationships in your data that you can query at any level of the hierarchy. You also can use sort keys for version-control purposes.
- Use secondary indexes efficiently
Secondary indexes are often essential to support the query patterns that your application requires. However, using secondary indexes inefficiently can add cost and reduce performance unnecessarily. Learn how to use sparse indexes, and use global secondary indexes for materialized aggregation queries and to create eventually consistent replicas.
- Understand how to store large items and attributes
DynamoDB currently limits the size of each item that you store in a table. If your application needs to store more data in an item than the size limits permit, you can try compressing one or more large attributes or breaking the item into multiple items (efficiently indexed by sort keys). You also can store the item as an object in Amazon S3 and store the Amazon S3 object identifier in your DynamoDB item.
- Handle time-series data by using one table per application per period
General design principles in DynamoDB recommend that you keep the number of tables you use to a minimum. For most applications, a single table is all you need. However, for time-series data, you can use one table per application per period.
- Manage many-to-many relationships
Adjacency lists are part of a design pattern that is useful for modeling many-to-many relationships in DynamoDB. More generally, they provide a way to represent graph data (nodes and edges) in DynamoDB.
- Implement a hybrid database system
In some circumstances, migrating from one or more relational database management systems to DynamoDB might not be advantageous. In these cases, it might be preferable to create a hybrid system.
- Model relational data in DynamoDB
When your business requires low-latency response to high-traffic queries, taking advantage of a NoSQL system generally makes technical and economic sense. DynamoDB helps solve the problems that limit relational system scalability by avoiding them.
- Query and scan data efficiently
Follow these tips about when to scan versus when to query and how to take advantage of parallel scans.
- Use global tables to replicate your table data across AWS Regions
DynamoDB global tables provide a fully managed solution for deploying a multi-region, multi-master database without having to build and maintain your own replication solution. When you create a global table, you specify the AWS Regions where you want the table to be available. DynamoDB performs all of the necessary tasks to create identical tables in these Regions and to propagate ongoing data changes to all of them.
- Watch Rick Houlihan’s “DynamoDB advanced design patterns” session from AWS re:Invent 2019
Many people have told us that watching Rick’s session—even if they had to watch it five times because there’s so much here to digest—changed the way they understand and work with DynamoDB. This session is the most-watched DynamoDB-related session year after year, and we cannot recommend it highly enough.
Follow DynamoDB best practices this year for the best performance and lowest costs! If you have questions or feedback about DynamoDB best practices, ping us on @DynamoDB on Twitter.
About the author
Craig Liebendorfer is a senior technical editor at Amazon Web Services. He also runs the @DynamoDB Twitter account.