So far we have talked about relational databases (tables, rows, columns, SQL). But there is another big world: NoSQL databases. The most important one in AWS is DynamoDB. Understanding what it is and when to use it gives you a powerful tool for cases where relational databases don’t fit well.

Relational vs NoSQL: two philosophies

Remember: a relational database (like RDS) organizes data in tables with a fixed schema (defined columns) and relates them to each other. It’s great when data has a clear and consistent structure.

A NoSQL database (like DynamoDB) is more flexible: it doesn’t require a rigid schema and is designed to scale to enormous amounts of data and requests with consistent speed.

Analogy:

  • A relational database is like a perfectly organized filing cabinet with labeled folders: everything has its exact place and relationships are well defined. Ideal for order and complex queries.
  • A key-value NoSQL database is like a huge locker room: you give a locker number (the key) and get what’s inside (the value), instantly, no matter how many lockers there are. Super fast for “give me this specific thing,” but not for “find me everything that meets these five conditions.”

What is DynamoDB

DynamoDB is AWS’s fully managed NoSQL database. Its distinctive features:

  • Key-value and document model: you store items identified by a key, and each item can contain flexible data (JSON-like documents).
  • Fully managed and serverless: there are no servers to manage at all. You don’t choose instance size or patch anything. You just create a table and use it.
  • Consistent performance at any scale: responds in milliseconds whether you have a thousand items or billions.
  • Virtually infinite scale: handles millions of requests per second effortlessly.

Why it’s so special: DynamoDB was designed to solve the scaling problems of Amazon.com (e-commerce). When millions of people shop at once on Black Friday, you need a database that doesn’t slow down no matter how much load it has. DynamoDB is that database.

DynamoDB basic concepts

  • Table: the container for your data (like a table, but without a rigid schema).
  • Item: each record (equivalent to a row).
  • Attributes: the fields of each item (they can vary between items: one can have fields that another does not).
  • Partition key: the main key by which each item is identified and located. Choosing it well is the most important part of the design.
Table "Users"
┌──────────────┬─────────────────────────────────────┐
│ id (key)     │  data (flexible)                     │
├──────────────┼─────────────────────────────────────┤
│ user#123     │  { name: "Ana", age: 30 }            │
│ user#124     │  { name: "Luis", city: "Madrid",     │
│              │    premium: true }                   │
└──────────────┴─────────────────────────────────────┘
   ↑ notice: each item can have different fields

When to use DynamoDB (its strengths)

DynamoDB shines when you need:

  • Massive scale and consistent performance: millions of users, huge spikes, millisecond latency.
  • Access by known key: “give me user user#123,” “give me the cart for customer X.” Direct and fast lookups.
  • Flexible structure: data that doesn’t fit a fixed schema or changes frequently.
  • Zero administration: you don’t want to manage anything about the database.

Real-world examples ideal for DynamoDB:

  • Shopping carts for an e-commerce site (access by user id, huge scale).
  • Player profiles in a video game with millions of users.
  • Sessions for app users.
  • Catalogs of products with variable attributes.
  • IoT: data from millions of sensors constantly sending information.

When NOT to use DynamoDB

DynamoDB is not the answer for everything. Avoid it when:

  • You need complex queries with many conditions, joins between tables, and rich relationships → for that, a relational database (RDS/Aurora).
  • Your data has many relationships between them that you query in various ways.
  • Your application is small and the relational model feels more natural to you.

Mental rule: If your queries are like “give me this specific item by its key” at large scale → DynamoDB. If they’re like “give me all orders from customers in Madrid who bought in March and spent more than €100” → relational database (SQL).

Advanced features (just so you know they exist)

  • DynamoDB Streams: emits an “event” every time something changes in the table. Used to trigger automatic actions (we’ll see this with Lambda in Chapter 14 and in event-driven architectures in Chapter 28).
  • On-demand vs provisioned: you can pay for actual usage (on-demand) or reserve capacity. On-demand is great for unpredictable workloads.
  • DAX: an in-memory cache for DynamoDB that makes it even faster (microseconds).
  • Global tables: replicas in multiple regions for users all over the world.

What you should remember

  • DynamoDB is AWS’s NoSQL database, fully managed and serverless (zero administration).
  • Uses a flexible key-value / document model and offers consistent millisecond performance at any scale.
  • It’s ideal for massive scale and known-key access (carts, profiles, sessions, IoT…), with flexible structure.
  • It’s not good for complex queries, relationships, and joins: for that use a relational database (RDS/Aurora).
  • Mental rule: “give me this item by its key” → DynamoDB; “find me everything that meets several conditions” → SQL.

In the next subchapter we’ll look at ElastiCache, for storing data in memory and speeding up your applications.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved