Volume 5 · Chapter 4 — Storage and Databases
NoSQL with DynamoDB
4.1 Introduction
Not every workload fits a relational database. For massive scale, predictable low latency, and simple access patterns, a NoSQL database is often the better tool, and on AWS that’s DynamoDB - a fully managed key-value and document database that delivers single-digit-millisecond performance at any scale. Knowing when to choose DynamoDB over a relational database, and understanding its data model and trade-offs, is a common interview topic that tests whether you match the data store to the workload rather than defaulting to one kind of database.
4.2 What DynamoDB Is
DynamoDB is a fully managed NoSQL database that stores items (records) in tables, identified by a primary key, without a fixed relational schema. It’s built for scale and speed: it delivers consistent single-digit- millisecond latency at essentially unlimited scale, automatically partitioning and distributing data behind the scenes, and it’s serverless in operation - you don’t manage servers, and it can scale capacity automatically with demand. Because it’s fully managed and horizontally scalable by design, it handles enormous request volumes without the operational tuning a relational database at scale requires. The trade-off is that you give up the rich relational model - complex joins and flexible ad-hoc queries - in exchange for scale, speed, and simplicity on well-defined access patterns.
4.3 The Data Model and Access Patterns
DynamoDB’s model centres on the primary key, which determines how data is partitioned and accessed. Because it’s optimized for key-based access rather than arbitrary queries, the golden rule is to design the table around your access patterns - you decide up front how you’ll read the data and model the keys (and secondary indexes) to serve those reads efficiently, rather than modelling normalized entities and querying flexibly later as you would relationally. This is the biggest mental shift: relational design models the data and queries flexibly afterward; DynamoDB design starts from the queries and shapes the data to serve them. Get the access-pattern-driven key design right and DynamoDB is blazing fast at scale; ignore it and you’ll struggle to retrieve data efficiently.
flowchart TB
Q{Workload characteristics?}
Q -->|Complex joins, ad-hoc queries,\nstrong relational integrity| Rel[Relational - RDS/Aurora]
Q -->|Massive scale, simple key-based access,\npredictable low latency| Dyn[DynamoDB - NoSQL]
Dyn --> Design[Design keys around access patterns first]
Rel --> Model[Model normalized entities, query flexibly] 4.4 Consistency, Capacity, and Features
DynamoDB offers read options: eventually consistent reads (default, cheaper, may briefly return slightly stale data) and strongly consistent reads (always the latest, at higher cost) - so you choose per read whether you need the most current value. Capacity comes in on-demand mode (pay per request, scales automatically - great for variable or unpredictable load) or provisioned mode (you set capacity, cheaper for steady predictable load). Useful features include DynamoDB Streams (a change feed that can trigger Lambda on data changes - great for event-driven pipelines), global tables (multi-Region replication for global low-latency access and DR), and automatic backups. These make DynamoDB not just fast storage but a building block for event-driven and globally-distributed designs.
4.5 When to Choose DynamoDB vs Relational
The choice is about matching the store to the workload. Choose a relational database (RDS/Aurora) when you need complex queries and joins, flexible ad-hoc querying, strong relational integrity, and multi-row ACID transactions - which is why a bank’s core ledger is relational. Choose DynamoDB when you need massive scale and consistent low latency with simple, well-defined key-based access patterns - session stores, user profiles, high-volume event or activity data, shopping-cart-style data, or any workload where predictable performance at scale matters more than query flexibility. Many systems use both: a relational system of record plus DynamoDB for the high-scale, simple-access parts. The anti-pattern is forcing a workload into the wrong model - complex relational querying onto DynamoDB, or extreme-scale simple lookups onto a single relational instance.
4.6 Banking Production Scenario
A bank keeps its authoritative account and transaction ledger in Aurora PostgreSQL for relational integrity and ACID transactions. Alongside it, DynamoDB handles high-scale, simple-access workloads: customer session data, where predictable single-digit-millisecond latency at scale matters and access is purely by key; and a high-volume activity/event store, keyed for the exact lookups the app performs. DynamoDB Streams trigger Lambda functions to feed downstream fraud and analytics pipelines as data changes. On-demand capacity absorbs unpredictable spikes without provisioning. The bank deliberately splits the workload - relational for the ledger’s integrity and complex queries, DynamoDB for scale-and-speed-with-simple-access - rather than forcing everything into one model, which is exactly the judgment good data architecture requires.
4.7 Troubleshooting: DynamoDB Issues
DynamoDB problems usually trace to modelling or capacity. Difficulty retrieving data efficiently, or needing full-table scans, means the keys weren’t designed around the access patterns - the fix is to model keys and secondary indexes for how you actually query, since DynamoDB rewards access-pattern-first design. Throttling under load means provisioned capacity is too low or a “hot” partition key concentrates traffic - use on-demand capacity or a better-distributed key. Reads returning slightly stale data are eventually consistent reads working as designed - use strongly consistent reads where you need the latest value. Attempting complex joins or ad-hoc queries signals the workload may belong in a relational database instead. The diagnostic mindset is to check that the key design matches the access patterns, capacity matches the load, and the read consistency matches the requirement - and to reconsider the data store choice if the workload is fighting the model.
When would you choose DynamoDB over a relational database, and what's the key design difference?
I choose DynamoDB over a relational database when the workload needs massive scale and consistent low latency with simple, well-defined access patterns, rather than complex querying and relational integrity. DynamoDB is a fully managed NoSQL key-value and document database that delivers single-digit-millisecond latency at essentially unlimited scale, automatically partitioning and distributing data, and operating serverlessly with capacity that can scale automatically. That makes it excellent for things like session stores, user profiles, shopping-cart data, and high-volume event or activity data - workloads where predictable performance at huge scale matters more than flexible querying, and where access is primarily by a known key. I choose a relational database like RDS or Aurora instead when I need complex queries and joins, flexible ad-hoc querying, strong relational integrity, and multi-row ACID transactions - which is exactly why a bank’s core account and transaction ledger is relational: it demands those transactional guarantees and rich querying. The key design difference, and the biggest mental shift, is how you model the data. In a relational database you model normalized entities and their relationships and then query them flexibly afterward with SQL - the data model comes first and queries are open-ended. DynamoDB is the opposite: because it’s optimized for key-based access rather than arbitrary queries, you design the table around your access patterns up front. You decide how you will read the data - which lookups the application performs - and you model the primary key and any secondary indexes specifically to serve those reads efficiently. Get that access-pattern-first design right and DynamoDB is blazing fast at any scale; ignore it and you end up needing inefficient full-table scans and fighting the model. So the decision is workload-driven - relational for complex queries, joins, and transactional integrity; DynamoDB for scale, predictable low latency, and simple key-based access - and the design difference is that relational modelling starts from the data and queries flexibly, while DynamoDB modelling starts from the queries and shapes the keys to serve them. Many real systems use both, keeping a relational system of record while offloading high-scale simple-access workloads to DynamoDB, and the mark of good judgment is matching each workload to the right model rather than forcing everything into one.
Chapter Revision Notes
- DynamoDB is a fully managed NoSQL key-value/document database with single-digit-millisecond latency at unlimited scale, serverless in operation.
- Design keys around access patterns first (queries drive the model) - the opposite of relational model-then-query.
- Reads: eventually consistent (default, cheaper) or strongly consistent (latest, costlier); capacity: on-demand (variable) or provisioned (steady).
- Streams (change feed → Lambda), global tables (multi-Region), and backups make it a building block for event-driven and global designs.
- Choose relational for complex queries/joins/ACID; DynamoDB for scale + low latency + simple key access - often use both.