DynamoDB is an incredibly powerful NoSQL Platform. Designing for it correctly requires a complete understanding of your business use case and mapping that to the building blocks provided by DynamoDB. NoSQL design requires a different mindset than RDBMS design. For an RDBMS, you can create a normalized data model without thinking about access patterns. You can then extend it later when new questions and query requirements arise.
By contrast, in Amazon DynamoDB, you shouldn’t start designing your schema until you know the questions that it needs to answer. Understanding the business problems and the application use cases up front is absolutely essential. This article provides DynamoDB best practices in a condensed form including schema-design, secondary indexes etc.
In a NoSQL database such as DynamoDB, data can be queried efficiently in a limited number of ways, outside of which queries can and will be expensive and slow. In DynamoDB, you design your schema specifically to make the most common and important queries as fast and as inexpensive as possible.
As opposed to a table in a relational database management system (RDBMS), in which the schema is uniform, a table in DynamoDB can hold many different types of data items at one time. In addition, the same attribute in different items can contain entirely different types of information.
You will use your provisioned throughput more efficiently as the ratio of partition key values accessed to the total number of partition key values increases.
A partition key design that doesn’t distribute I/O requests evenly can create “hot” partitions that result in throttling and use your provisioned I/O capacity inefficiently. You should structure the primary key elements to avoid one “hot” (heavily requested) partition key value that slows overall performance. You can use write sharding to distribute the workloads evenly, for e.g., you can add a random number to the partition key values to distribute the items among partitions. Or you can use a number that is calculated based on something that you’re querying on.
Determine the access patterns that your application requires, and estimate the total read capacity units (RCU) and write capacity units (WCU) that each table and secondary index requires.
Sort keys are useful for the following:
begins_with
, between
, >
, <
, and so on.country
, to a neighborhood
, and everything in between.v0_
) at the beginning of the sort key, and one should have a version-number prefix of one (such as v1_
). Every time the item is updated, use the next higher version-prefix in the sort key of the updated version, and copy the updated contents into the item with version-prefix zero. This means that the latest version of any item can be located easily using the zero prefix.#database #dynamodb #aws #nosql #nosql-database