Overview
DynamoDB is a database that appears quite a lot at the exam from an architectural point of view. It is fully managed, highly available, with replication of data across multiple AZs. It is cloud native (AWS proprietary) and a NoSQL database, so it is not a relational database like RDS and Aurora, although it still has transaction support.
Related: 02-AWS-Lambda (Lambda commonly uses DynamoDB as the database for an API), 10-DynamoDB-Advanced-Features.
Key Characteristics
| Characteristic | Detail |
|---|---|
| Scale | Millions of requests per second, trillions of rows, hundreds of terabytes of storage (internally distributed) |
| Performance | Single-digit millisecond latency, fast and consistent |
| Security | Integrated with IAM for security, authorization and administration |
| Cost | Low cost, with auto-scaling capabilities |
| Maintenance | No maintenance or patching, always available |
| Table classes | Standard (frequently accessed data) and Infrequent Access (IA) (infrequently accessed data) |
The course said on-demand costs 2 to 3 times more than provisioned and is "at your own risk". On-demand throughput prices were cut 50% in 2024-11 and AWS now recommends on-demand as the default for most workloads. The exam may still use the course figure. AWS source
You do not provision a database. The database is already there (the service is named DynamoDB). You create a table and say how much capacity you want in it.
Tables, Items and Attributes
- DynamoDB is made of tables. You never create a "database" like in Aurora or RDS.
- Each table has a primary key, decided at creation time.
- A table can have an infinite number of items (rows).
- Each item has attributes (like columns). Attributes can be added over time and can be null.
- Maximum item size is 400 KB. DynamoDB is not there to store very large objects.
- Supported data types: Scalar types (String, Number, Binary, Boolean, Null), plus List, Map and Set.
- The primary key is made of a partition key, and optionally a sort key.
In RDS or Aurora you can add columns over time, but it is a complicated process and schemas are hard to evolve. In DynamoDB you add attributes without any prerequisite. If the exam says the schema needs to rapidly evolve, DynamoDB is a much better choice than Aurora or RDS.
Capacity Modes
You control how the table capacity is managed with one of two modes.
| Feature | Provisioned Mode (default) | On-Demand Mode |
|---|---|---|
| Capacity planning | Plan beforehand: say how many reads and writes per second you expect | None. Scales automatically with the workload |
| Units | RCU (Read Capacity Units) and WCU (Write Capacity Units) | No concept of RCU and WCU |
| Billing | Pay for every provisioned RCU and WCU | Pay exactly for what you use, for every read and every write |
| Auto scaling | Optional. Increases or decreases RCU/WCU over time based on load | Not needed |
| Cost | Cost saving | Pay-per-request pricing; on-demand prices were cut 50% in 2024-11, so the old cost penalty no longer applies |
| Best for | Predictable load that evolves smoothly | Unpredictable workloads or steep, sudden spikes |
- Application scaling from 1,000 transactions to 1 million transactions in less than a minute -> provisioned mode does not scale fast enough -> On-Demand.
- A workload with almost no transactions (e.g. four or five a day) -> On-Demand, you only pay for those few transactions.
- Predictable load and cost saving -> Provisioned (with auto scaling).
Hands-On Walkthrough
Create a table
- Open DynamoDB and click Create table. There is no such thing as creating a database, you create a table right away, which makes it a serverless database.
- Table name
DemoTable. Choose a partition key (user_id) and optionally a sort key (none here). The combination of the two makes the primary key. - Choose Customize settings to see all options.
Read/write capacity settings
- On-demand: pay for the actual reads and writes. Great for unpredictable workloads, and AWS now recommends it as the default for most workloads.
On-demand prices were cut 50% in 2024-11; the course said 2 to 3 times more expensive. AWS source
- Provisioned: manage and optimize cost by allocating read and write capacity in advance. Read and write each have auto scaling on or off.
- Auto scaling off: set fixed capacity units (e.g. 10 read and 5 write).
- Auto scaling on: set a minimum (e.g. 1), a maximum (e.g. 100) and a target utilization (e.g. 70%). Auto scaling manages capacity to match about 70% utilization, for both read and write capacity.
- The demo sets auto scaling off with 1 RCU and 1 WCU.
- Indexes are covered in a later lecture, so they are skipped here.
- A capacity calculator exists to find the right read/write capacity. It is more complex and more relevant for the developer exam.
- With 1 RCU and 1 WCU the console shows an estimated cost of 71 cents per month, which gives pricing information.
- Enable encryption at rest, then click Create table.
Insert items
- Open the table and click View items, then Create item.
- Item 1:
user_id=stephane_123, add attributesname(String) = Stephane Maarek,favorite_movie= Memento,favorite_number(Number) = 42. - Item 2:
user_id=alice_456,name= Alice Doe,favorite_movie= Pocahontas, plus an extra attributeage= 23. - Alice has a different set of attributes than Stephane. Not all items need all attributes, every item can have different attributes. This shows the power of a NoSQL table versus SQL.
How to set read/write capacity units or on-demand mode, and how to insert data into a table.
Questions & Answers
Q1: What is DynamoDB and what is it good at?
Answer:
A fully managed, highly available, multi-AZ, NoSQL database with single-digit millisecond latency, scaling to millions of requests per second and hundreds of terabytes. Choose it when the schema must evolve rapidly.
Q2: What is the maximum item size?
Answer:
400 KB. It is not for very large objects.
Q3: Provisioned or On-Demand?
Answer:
Provisioned (default, RCU/WCU, optional auto scaling) for predictable load and cost saving. On-Demand for unpredictable workloads, sudden spikes (1,000 to 1 million transactions in under a minute) or very rare traffic. On-demand prices were cut 50% in 2024-11 and AWS now recommends it as the default for most workloads.
The course said on-demand costs 2 to 3 times more; prices were cut 50% in 2024-11. The exam may still use the course figure. AWS source
Q4: What makes up the primary key?
Answer:
A partition key and optionally a sort key, chosen at table creation.
Q5: What are the two table classes?
Answer:
Standard for frequently accessed data and Infrequent Access (IA) for infrequently accessed data.
Check yourself
Quiz
Flashcards
Click the card (or focus it), then use ← → to move and Space to flip.