What Is Amazon DynamoDB? Design Keys and Tables Around Access Patterns
Amazon DynamoDB is a serverless NoSQL database managed by AWS that stores key-value and document data. Its central design principle is to identify the questions an application must answer before creating tables, then choose primary keys and indexes that support those access patterns. This helps determine when DynamoDB fits and when a relational database may be simpler.
Amazon DynamoDB is a serverless NoSQL database managed by AWS that stores key-value and document data. Its central design principle is to identify the questions an application must answer before creating tables, then choose primary keys and indexes that support those access patterns. This helps determine when DynamoDB fits and when a relational database may be simpler.
What kind of database is DynamoDB?
DynamoDB organizes data into tables, items, and attributes. A table contains items, and each item contains attributes. An orders table, for example, might store an order ID, customer ID, status, and creation time. Attributes other than the key can vary between items, which makes the data model flexible; however, the rules that uniquely identify each item must be defined when the table is created.
AWS manages much of the routine infrastructure work, such as servers, operating systems, and database engine maintenance. Applications read and write items through an SDK or API. “Managed” does not mean that data modeling is automatic. If the data model does not fit the way the application reads it, the result can be unnecessary reads, awkward searches, or higher costs. DynamoDB does not provide the relational JOIN operator, so applications that need related data together often store it in a way that fits their access patterns or add indexes.
How do partition and sort keys define access?
A primary key uniquely identifies an item. DynamoDB supports a simple primary key with one partition key, or a composite primary key with a partition key and a sort key. DynamoDB hashes the partition-key value to determine where data is distributed. With a composite key, multiple items can share a partition-key value and be distinguished and ordered by their sort-key values.
For example, using CustomerId as the partition key and OrderDate#OrderId as the sort key lets an application query a customer's orders and narrow them to a date range. If the application must find an order directly by its order ID, that ID needs to be part of a key or an index. Do not assume that any attribute can be searched efficiently later. If a lookup does not match a table or index key, it may require a Scan or additional processing in the application.
Choose partition keys that avoid concentrating too much traffic on one value. If every item uses the same key value, such as ORDER, data and requests can become concentrated. A high-cardinality value that is also useful for real queries is a reasonable starting point, but cardinality alone is not enough. Check whether one customer or a steadily increasing time-based key could attract a disproportionate share of data and read/write traffic.
How do Query, Scan, and secondary indexes differ?
Query retrieves items with a specified partition-key value from a table or secondary index. For a composite key, a sort-key condition can narrow the results by range or prefix. It fits questions that can be expressed through keys, such as “orders for customer 42 during October 2026.”
Scan reads every item in a table and filters for matching results. It can be useful for a small table, an administrative task, or an occasional full inspection. But a filter that returns fewer items does not erase the data that was evaluated during the read. Frequent scans of a large table can increase read consumption and latency. Before using Scan for a core API or user-facing search, consider whether a key or index can support the query.
A secondary index provides a query path different from the table's primary key. A global secondary index (GSI) can use partition and sort keys that differ from the base table. This adds storage and write-capacity considerations, and reads from a GSI are eventually consistent. An index is not a free-form search feature: its usefulness must be weighed against its maintenance and storage costs.
Example: supporting customer order history and operations searches
The following is an illustrative order-service scenario, not a tested implementation. Suppose the service must (1) list a customer's orders by date, (2) look up one order by order ID, and (3) let an operator find orders awaiting processing.
A base key of CustomerId plus OrderDate#OrderId can support the first access pattern with Query and a date condition. For direct lookup by order ID, consider a separate table keyed by that ID or a GSI whose partition key is the order ID. To support the third pattern, an index might use Status as its partition key. But if status has only a few possible values, writes may concentrate on one key; status changes also require index updates. Depending on the requirements, multiple tables may be easier to understand for a small service. A single-table design may be worth considering when the application often retrieves multiple related entity types together.
These keys and indexes are not the only valid design. Before implementation, document each access pattern's frequency, response size, write rate, retention period, concurrency, and risk of traffic hotspots. Then test queries and capacity with representative data. AWS likewise recommends identifying required access patterns before defining the schema.
How should you choose consistency and throughput modes?
Reads are eventually consistent by default. A read immediately after a successful write might not show the change, although a later read should. Tables and local secondary indexes (LSIs) can also support strongly consistent reads. Global secondary indexes and DynamoDB Streams do not support strongly consistent reads. Choose consistency based on the need: an order status immediately after payment may require the newest value, while a listing may tolerate a brief delay.
For throughput, choose between on-demand and provisioned capacity modes. On-demand requires less advance capacity planning and charges per request, making it convenient for a new service or variable traffic. Provisioned mode sets read and write capacity and can be configured to scale with demand; it is worth evaluating for workloads that are relatively predictable. In either mode, key design, request size, index writes, and sudden traffic changes affect cost and throttling risk. Quotas and prices can vary by Region and over time, so check current AWS documentation before deployment.
When should you choose DynamoDB over a relational database?
DynamoDB can fit workloads that need to handle high request volumes through known access patterns while reducing server and database-engine operations. A relational database or analytical store may be simpler when the application depends on ad hoc combinations of filters, complex joins and relational integrity, or analytical queries. Decide by checking whether the application's real questions can be expressed efficiently through DynamoDB keys and indexes, rather than relying on a general claim that NoSQL is faster.
Before adopting DynamoDB, write down the required read and write patterns. For each one, map the partition key, sort key, index, and expected result size. Then use representative load to examine consistency, capacity mode, hot-key risk, and index updates. If an important question can only be answered with frequent scans or constant data-model workarounds, reconsider the model or database choice.
References
[What is Amazon DynamoDB?](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)
[Core components of DynamoDB and primary keys](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html)
[Modeling DynamoDB around access patterns](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql.html)
[Read and write operations, including Query and Scan](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html)
[DynamoDB read consistency](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html)
[DynamoDB throughput capacity modes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/capacity-mode.html)
[DynamoDB partitions and data distribution](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.Partitions.html)