- Subject
- Software
- Date
- Read
- 16 min
SQL vs NoSQL on AWS: start with your access patterns
Why I reach for DynamoDB on AWS, what it can do that people assume it can't, its real limits, and where SQL still wins.
Contents
- The two types
- SQL on AWS: transactional vs analytical
- How SQL handles change
- Why I reach for DynamoDB on AWS
- Primary keys: partition key and sort key
- The misconception: “DynamoDB can’t do what SQL can”
- Global secondary indexes
- Local secondary indexes
- You can’t redefine your keys
- Define your access patterns first
- Eventual vs strong consistency
- Hot partitions
- Transactions and ACID
- Single-table vs multi-table
- Where SQL still wins
- The takeaway
- Further reading
I think a lot of people pick a SQL database by default. It’s what they learned first, it’s easy to run locally, and you don’t have to know how you’ll query your data before you start. That last part is exactly why it feels easy, and exactly why NoSQL feels hard.
I’ve built production systems on DynamoDB. I also built a personal finance tool, a small app that pulls in my bank transactions so I can ask questions about my spending, and it runs on SQLite. Neither is “better.” The way you access the data picks the database, and on AWS I end up reaching for DynamoDB more often than not.
The two types
Relational (SQL)
Relational databases store data in tables with a fixed schema. Columns, types, and constraints are declared up front, rows relate to each other through foreign keys, and you can ask almost any question after the fact by joining tables together. The big strengths are query flexibility and data integrity.
The common ones are PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, and SQLite.
NoSQL
NoSQL is a broad label for databases that don’t use the relational model. They give up some query flexibility in exchange for scale, speed, or a data shape that fits the problem better. The main families:
| Type | What it’s good at | Examples | On AWS |
|---|---|---|---|
| Key-value | Fast lookups by a key you design | DynamoDB, Redis, Valkey | DynamoDB, ElastiCache, MemoryDB |
| Document | JSON-like records with nested fields | MongoDB, Couchbase | DocumentDB |
| Wide-column | Huge write volumes across many machines | Cassandra, ScyllaDB | Keyspaces |
| Graph | Relationships as the main thing you query | Neo4j | Neptune |
| Time-series | Metrics and events over time | InfluxDB | Timestream |
DynamoDB sits in the key-value and document families. Every item is found by a key you design, and the database is built to make those lookups fast at any scale. That’s the one I’ll focus on here.
Both types are important. The mistake is choosing one out of habit instead of out of the shape of your data.
SQL on AWS: transactional vs analytical
Before comparing SQL with NoSQL, it’s worth separating the two kinds of SQL database AWS sells, because they do different jobs and aren’t interchangeable.
Transactional databases handle an application’s reads and writes: create an order, update a profile, fetch one user’s settings.
- Amazon RDS: managed PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, and Db2. You pick an instance size and AWS handles backups, patching, and failover. A fixed instance is easy to reason about when traffic is steady and predictable.
- Amazon Aurora: AWS’s own MySQL- and PostgreSQL-compatible engine, with storage separated from compute. Existing PostgreSQL drivers, tools, and queries work against it unchanged.
- Aurora Serverless v2: Aurora that scales capacity up and down with load, which suits bursty or unpredictable traffic. Since late 2024 it can scale all the way to zero, with the catch that waking back up takes around 15 seconds.
- Aurora DSQL: a serverless, distributed, PostgreSQL-compatible database that went generally available in May 2025. It’s AWS’s answer to “I want SQL but I don’t want to think about servers.”
Analytical databases handle aggregations and reporting over large datasets. Redshift and Redshift Serverless speak PostgreSQL-flavored SQL, but they’re columnar warehouses built to scan billions of rows, not to take small writes from an application.
When people argue SQL vs NoSQL, they almost always mean transactional SQL, so that’s the comparison here.
How SQL handles change
Schema and migrations
In SQL, the schema has to exist before the data does. When the data model changes, you write a migration, a versioned SQL script that alters the schema, and run it against the database. Tools like Flyway and Liquibase track which migrations have run and apply only the new ones.
-- V1__create_reminders.sql
CREATE TABLE reminders (
reminder_id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
message TEXT NOT NULL,
due_at TIMESTAMPTZ NOT NULL
);
-- V2__add_status.sql, added later
ALTER TABLE reminders ADD COLUMN status TEXT NOT NULL DEFAULT 'pending';
There’s a real upside: the migration history documents how the data model evolved, and you can read it top to bottom. The tool itself is lightweight. The discipline isn’t: every schema change is a migration file, a code review, and a coordinated deployment.
And migrations on a live production table are where a lot of outages come from:
- Table locking. Some
ALTER TABLEoperations lock the table while they run. On a large, busy table that can block reads and writes for seconds to minutes. Adding a nullable column or building the index withCREATE INDEX CONCURRENTLYavoids most of it, but you have to know to do that. - Failed migrations. A migration that fails halfway can leave the database in a partial state, and some changes don’t roll back cleanly.
- Deployment coupling. The migration has to land before, or with, the code that depends on it. Get the order wrong and production breaks.
- Schema drift. If someone changes the database by hand, the migration tool’s idea of the schema no longer matches reality.
Indexes
This is where SQL is genuinely more forgiving. Without an index a query scans every row; with one, the database jumps straight to the rows it needs. B-tree indexes handle equality and range filters, and composite indexes cover queries that filter on several columns.
The important part: you don’t have to plan them. If a new query shows up after launch and it’s slow, you add an index and the database starts using it. No application change, no redeploy.
-- added after launch, when a new query pattern showed up
CREATE INDEX idx_reminders_user_due ON reminders (user_id, due_at);
Keep that in mind when we get to DynamoDB’s indexes, because it’s the biggest difference between the two.
Read consistency
Reads from an Aurora primary instance always return the latest data. Read replicas take heavy read traffic off the primary, at the cost of a little replication lag, usually milliseconds. Most application reads go to the primary and never think about it.
Why I reach for DynamoDB on AWS
It’s actually serverless. There’s no instance to size, patch, or place in a VPC, and no connection pool to manage. That last one matters a lot with Lambda. PostgreSQL holds a persistent connection per client, and every concurrent Lambda opens its own. A traffic spike can exhaust the database’s connection limit. The fix is a pooler: RDS Proxy (managed) or PgBouncer (run it yourself). A long-running server on Fargate can keep its own pool, but that’s still something to manage. DynamoDB doesn’t have the problem: every request is an HTTPS call.
You pay for what you use. In on-demand mode you’re billed per read and write, so a side project or a new product with a handful of users costs close to nothing. AWS cut on-demand prices by 50% in November 2024 and now recommends it as the default for most workloads. The free tier also includes 25 GB of storage, plus 25 read and 25 write capacity units for provisioned tables, every month.
No migrations. Items don’t have to share a shape beyond their keys. Adding a field is just writing it. Old items without it still work, with no lock, no migration file, and no deployment ordering. The catch is that older items won’t have the field, so your code has to handle it being missing. The migration doesn’t disappear; it moves into your application code. For most changes, that’s a much safer place for it to live.
It plugs into everything. IAM permissions per table, encryption at rest by default, Lambda triggers off DynamoDB Streams, TTL to expire old items automatically, and a few lines of CDK to define a table. In the AWS ecosystem it’s the path of least resistance.
It scales. Data is replicated across three Availability Zones with a 99.99% availability SLA, and partitions are split automatically as you grow. During Prime Day 2025, DynamoDB peaked at 151 million requests per second. The DynamoDB paper from USENIX ATC 2022 explains how it keeps single-digit-millisecond latency at that size. Relational databases scale too, but mostly by getting a bigger machine and adding read replicas; scaling writes across machines is where they get hard.
Primary keys: partition key and sort key
Everything in DynamoDB starts with the primary key. It comes in two forms:
- Simple: just a partition key. Every item needs a unique value.
- Composite: a partition key plus a sort key. Many items can share a partition key as long as their sort keys differ.
DynamoDB hashes the partition key to decide which physical partition stores the item. Items with the same partition key live together, sorted by sort key, so you can fetch them as a group in one query:
PK: user#42 SK: 2026-11-02T09:00#r-1 → reminder 1
PK: user#42 SK: 2026-11-03T17:30#r-2 → reminder 2
PK: user#42 SK: 2026-11-10T08:00#r-3 → reminder 3
PK = "user#42" returns all three in due-date order. Add SK < "2026-11-04" and you get
the ones due before the 4th.
The misconception: “DynamoDB can’t do what SQL can”
The common objection is that NoSQL can’t handle the things a relational database can: filtering, sorting, relationships. My view is that you can get most of that, as long as you design your schema for the questions you’re going to ask.
Take that reminders feature. A background job wakes up every minute and needs every reminder that’s pending and due, across all users. In SQL you’d write:
SELECT * FROM reminders
WHERE status = 'pending' AND due_at <= now();
DynamoDB has no WHERE clause over arbitrary columns, and the table is keyed by user, not
by status. Instead you build an index around that exact question.
Global secondary indexes
A global secondary index (GSI) is a second copy of your table’s data, keyed
differently. The table is keyed by user so you can fetch one user’s reminders; a GSI keyed
by status and due time answers “what’s due right now?” DynamoDB keeps the index in sync
for you on every write, and you query it like the table, just with an IndexName.
With that index the reminder query becomes a single indexed lookup:
status = "pending" AND dueAt <= now
It reads only the reminders that are due, doesn’t scan the table, and doesn’t slow down as the table grows. GSIs are how you get most of SQL’s flexibility back.
They have real limits, though:
- There’s a default quota of 20 GSIs per table (DynamoDB quotas). Each new question that needs a different key costs you one. If you’re heading toward 20, your access patterns probably aren’t settled, which is a hint SQL might fit better.
- Each index answers one question, and you have to plan it. If you later want “reminders created on a specific device,” that’s another index and another deploy. Compare that with SQL, where you add an index and nothing else changes.
- GSI reads are always eventually consistent. A write to the table shows up in the index a moment later, not instantly. More on that below.
- Every write is paid for again in each index that includes the item. At low volume it’s negligible; at high volume it adds up.
- You can’t change an index’s keys. You delete the GSI and create a new one, and DynamoDB backfills it from the table.
Local secondary indexes
A local secondary index (LSI) is narrower: it keeps the table’s partition key and gives you a different sort key. Think of it as another way to sort items within the same partition.
Table: PK: user#42 SK: dueAt#reminderId → by due date
LSI: PK: user#42 SK: createdAt#reminderId → by creation date
That answers “user 42’s reminders, newest first” without a GSI, but only within one user. For anything across users, you need a GSI.
The constraints are stricter than a GSI’s:
- You can only create them when you create the table. You can’t add one later.
- There’s a maximum of 5 per table.
- Each partition key value is capped at 10 GB across the table and all its LSIs. A user with an unusually large amount of data can hit it.
- They support strongly consistent reads, which GSIs don’t.
For most systems, GSIs are the right choice. LSIs are a niche optimization for when you know every sort order at design time and need strong consistency within a partition.
You can’t redefine your keys
This is the limit that bites hardest. A table’s partition key and sort key are fixed
when you create it. There’s no ALTER TABLE. If you get them wrong, the fix is to create
a new table with the right keys, copy every item over, point your code at it, and delete
the old one.
That’s the strongest argument for doing the design work up front.
Define your access patterns first
This is the one thing I always push on when someone starts with DynamoDB: write down your access patterns before you design the table. In SQL you design the schema first and write queries later. In DynamoDB it’s backwards, and that’s the biggest mental shift.
The process:
- List every question the application will ask the database, such as “get a user’s devices,” “get the last 20 messages in a conversation,” or “find reminders that are due.”
- Design the partition and sort key around the most common or most performance-critical one.
- Add a GSI for each pattern the table’s keys can’t serve.
- Anything left over needs a scan. That’s fine at low volume and expensive at scale.
AWS’s own guide, First steps for modeling relational data in DynamoDB, says the same thing: don’t start designing until you know the questions.
Eventual vs strong consistency
DynamoDB confirms a write once it’s durable, then propagates it to the other replicas over the next few milliseconds. Reads come in two kinds:
- Eventually consistent (the default) can be served by any replica. Right after a write there’s a small window where you might get the old value. They cost half as much.
- Strongly consistent always reflects every write that completed before the read. They cost twice as much, and only work on the table and its LSIs, never on a GSI.
When it matters: a user creates a reminder and the app immediately reloads their list. With an eventually consistent read, the new reminder might not be there yet. That’s a read-after-write, and it’s the case for a strongly consistent read on the table:
const result = await client.send(new QueryCommand({
TableName: "reminders",
KeyConditionExpression: "PK = :pk",
ExpressionAttributeValues: { ":pk": "user#42" },
// Table or LSI only; a GSI query rejects this.
ConsistentRead: true,
}));
The background job that sends due reminders doesn’t care about a few milliseconds of lag, so it reads the GSI with the cheaper default.
Hot partitions
DynamoDB spreads data across partitions by hashing the partition key. Each partition can handle up to 3,000 reads and 1,000 writes per second. If a large share of your traffic lands on one partition key value, that partition becomes hot: it gets throttled while the rest of the table sits idle.
The reminders index above has exactly this problem. Every pending reminder shares the key
status = "pending", so at real scale all of that traffic piles onto one partition. It
works fine for a small app and falls over for a large one.
Practices to avoid it:
- Pick high-cardinality partition keys. User IDs, order IDs, and device IDs have millions of distinct values. Status, type, country, and today’s date have a handful.
- Shard keys that have to be low-cardinality. Add a suffix like
pending#0throughpending#9and spread writes across them, then query all ten when you read. AWS calls this write sharding. - Use sparse indexes. Only items that have the index’s key attribute appear in a GSI. Set the attribute on pending reminders and remove it once they’re sent, and the index only ever holds the work that’s left to do. (Sparse indexes)
- Watch out for time-based keys. Keying by “today” sends every write of the day to one partition. Combine the date with something more spread out.
- Measure before guessing. CloudWatch Contributor Insights shows which keys get the most traffic.
DynamoDB’s adaptive capacity smooths over a lot of uneven traffic automatically, but it can’t save a design where one key gets most of the load.
Transactions and ACID
ACID is the set of guarantees that keep data correct through crashes and concurrent writes:
- Atomicity: a transaction is all or nothing. If one write fails, they all roll back.
- Consistency: a transaction moves the database from one valid state to another, and never breaks a constraint along the way.
- Isolation: concurrent transactions don’t see each other’s half-finished work.
- Durability: once committed, it stays committed, even if the server crashes a moment later.
SQL gives you all of that on every write, by default. DynamoDB has it too, through
TransactWriteItems,
with limits: up to 100 actions and 4 MB per transaction, and each item in it costs two
writes (one to prepare, one to commit).
You need it when two writes must succeed or fail together, like creating a reminder and incrementing the user’s reminder count, or when you read something and write based on it and can’t let another request sneak in between. For a single independent write, you don’t.
Single-table vs multi-table
In a relational database, each entity type gets its own table. In DynamoDB, single-table design puts several entity types (users, devices, reminders) into one table, with keys arranged so related items sit next to each other and come back in one query:
PK: USER#42 SK: PROFILE → the user
PK: USER#42 SK: DEVICE#a1 → one of their devices
PK: USER#42 SK: REMINDER#2026-11-02 → one of their reminders
PK = "USER#42" returns the user and everything they own in one request.
PK = "USER#42" AND begins_with(SK, "DEVICE#") returns just the devices. Note that the
prefix trick works on the sort key. A prefix on the partition key alone, like USER#,
doesn’t let you query “all items of a type”; that takes a scan or a GSI on a type
attribute.
Alex DeBrie’s The What, Why, and When of Single-Table Design is the best explanation of it, and his follow-up on the AWS blog lays out both sides.
My opinion: only go single-table when it makes a query more efficient. If putting two
entities in one table lets you fetch them together in one request instead of two, that’s a
real gain. But things that merely feel related don’t belong together if you never query
them together. You give up readability (anyone opening the table has to decode overloaded
PK/SK values) and you get nothing back for it.
In my own projects I default to a table per entity, because most entities are read on their own. Where two things are always read together, they share a table and a key structure.
Where SQL still wins
I’m not anti-SQL. My finance tool uses SQLite on purpose. Its whole job is answering questions I didn’t plan for: spending by category for the last three months, every transaction from one merchant, a month compared with the same month last year. That’s ad-hoc querying, aggregates, and joins, which is exactly what relational databases are built for. Doing it in DynamoDB would mean predicting every question up front, which defeats the purpose.
Pick SQL when:
- You don’t know your access patterns yet, or they’ll keep changing.
- You need ad-hoc queries, reporting, or analytics.
- You or your team want to open the database and query it directly when debugging.
- Your data is heavily relational and you need joins across many entities.
- You want the database itself to enforce the schema, constraints, and foreign keys.
Pick DynamoDB when:
- You know how the data will be read, and those patterns are stable.
- You’re on AWS, especially with Lambda.
- You’ll be adding fields over time and don’t want migrations.
- You want to pay per request and never think about servers or connections.
- You need predictable performance at any scale.
The takeaway
Don’t default to SQL just because it’s familiar, and don’t avoid DynamoDB because someone told you NoSQL can’t handle “real” data. Most of what people think they lose, they get back with indexes and a schema designed around their access patterns. Write those patterns down first, pick keys that spread the load, and the database choice usually makes itself.