Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

DynamoDB vs Relational Databases

Compare DynamoDB with SQL databases: schema, joins, queries, scaling, transactions and cost, and learn when each approach is the right choice.

If you know SQL, DynamoDB can feel like a step backwards: no joins, no GROUP BY, no free-form queries. It is not a worse relational database. It is a different tool, built on a different bargain, and the sooner you stop expecting SQL habits to work, the sooner it becomes pleasant to use. This lesson contrasts the two models so you can decide which one fits a project.

The core difference: model data, or model questions

In a relational database you normalize the data first. You split it into tables with no duplication and ask questions later in SQL, joining tables as needed. The database planner figures out how to answer. This is flexible but the cost of a query grows with the amount of data it touches, and joins across big tables get slow.

In DynamoDB you start from the questions (your access patterns) and shape the data to answer each one with a single, cheap lookup. You accept duplication and denormalized items. In return, every request is fast and predictable regardless of table size.

flowchart TB
    subgraph R["Relational design"]
    R1["1. Model entities"] --> R2["2. Normalize"] --> R3["3. Write SQL for any question"]
    end
    subgraph D["DynamoDB design"]
    D1["1. List access patterns"] --> D2["2. Choose keys and indexes"] --> D3["3. Store items to fit them"]
    end

The order of the steps is reversed.

Side by side

Topic Relational (SQL) DynamoDB
Schema Fixed columns per table Only the key is fixed
Query language SQL, ad hoc API operations plus expressions
Joins Yes No, model them in the keys
Aggregates COUNT, SUM, GROUP BY None built in, precompute or export
Scaling Vertical, plus read replicas, sharding is manual Horizontal and automatic
Latency Varies with query and load Single-digit milliseconds
Transactions Full, across tables Supported, limited to 100 items and priced higher
Consistency Strong by default Eventual by default, strong on request
Operations Servers, patches, backups to manage Fully managed
Cost model Instance hours Storage plus per request or reserved capacity

Same question, two designs

Imagine a blog. The question: "show a post with its ten latest comments."

In SQL you keep posts and comments tables and join or run two queries. In DynamoDB you give both kinds of item the same partition key (the post id) and distinguish them with the sort key, so one Query returns the post and its comments together, already ordered.

The stand-in below models both approaches: a relational-style lookup that filters a list of comments, and a keyed layout where the sort key keeps everything for a post together and ordered.

Python Stand-in: join in code vs one keyed read

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The loop in the relational half checks every comment. The keyed half only touches items that share the partition key. In the real service, the second approach stays fast even with billions of comments.

What you give up

  • Ad-hoc queries. "Which customers in Spain bought more than three items last March?" is easy in SQL. In DynamoDB it needs an index designed for it, a scan, or an export to another tool.
  • Referential integrity. No foreign keys. If you delete a customer, your code (or a Streams-driven cleanup) must remove related items.
  • Flexible aggregation. Counts and sums are maintained by you, for example with atomic counters in an item.
  • Easy schema change. There is no migration for columns, but changing a key design means writing a new table and copying data.

What you gain

  • Predictability. Each request touches a bounded amount of data, so latency does not creep up as you grow.
  • No capacity planning ceremony. On-demand mode scales up and down with traffic.
  • Operational silence. No patching, failover drills or storage growth chores.
  • Event hooks. Streams and TTL turn data changes into triggers.

Deciding which to use

Pick DynamoDB when:

  • you know your access patterns, and they are mostly lookups by key or by key range,
  • traffic is high, spiky or unpredictable,
  • you value predictable latency and a hands-off service.

Pick a relational database when:

  • you need flexible reporting and the questions keep changing,
  • the data is deeply interconnected and queried across many entities,
  • your team is small, the data fits comfortably on one server, and the simplest tool wins.

Many systems use both: DynamoDB for the hot path (sessions, carts) and a relational database or warehouse for reporting, fed by Streams.

Translating habits

SQL habit DynamoDB equivalent
SELECT * FROM t WHERE id = 5 GetItem with the key
... WHERE user = 5 ORDER BY at Query with a sort key
CREATE INDEX on any column Add a secondary index, which duplicates data
JOIN Co-locate items under one partition key
UPDATE ... SET n = n + 1 UpdateItem with an ADD or SET expression
BEGIN ... COMMIT TransactWriteItems (up to 100 items)
Python Stand-in: maintain a count instead of using COUNT(*)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The counter is read in one lookup. The sum over orders is what you would be forced to do without a precomputed value.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the first step when designing a DynamoDB table?

    DynamoDB design starts from the questions you must answer, because the key design has to serve them directly.
  2. 2. How do you handle a one-to-many relationship such as a post and its comments?

    Items that share a partition key are stored together and can be read with one Query, ordered by sort key.
  3. 3. Which is a genuine weakness of DynamoDB compared with SQL?

    DynamoDB reads stay fast at any size, but unplanned joins and aggregates are not supported without extra design or tools.
  4. 4. Which workload suits a relational database better?

    Flexible reporting across many related tables is where SQL shines. The other examples are simple key lookups.

Summary

  • Relational design models data first and asks questions later; DynamoDB models the questions first.
  • DynamoDB has no joins, no ad-hoc queries and no built-in aggregates, but gives predictable speed at any scale.
  • One-to-many relationships are modelled by sharing a partition key and varying the sort key.
  • Aggregates and integrity rules move into your application or event handlers.
  • Many systems combine DynamoDB for hot paths with SQL for reporting.

Next: Attribute Data Types