# Postgres or DynamoDB for a new SaaS?

By Vishal Kumar · Published 2026-11-05 · Updated 2026-11-13
Source: https://fungyaan.com/p/postgres-or-dynamodb
Tags: databases, postgres, dynamodb, aws, saas

**The verdict, which the numbers below will earn:** for most new SaaS products, **PostgreSQL**. Early on, you don't know all the questions your product, your customers and your own team will ask of the data, and PostgreSQL answers new questions with a new query (and maybe an index). **DynamoDB** is excellent when your access patterns are few, known and stable, and you want hands-off scaling and predictable latency at any size. But every question you didn't design the table for becomes either a full scan (paid per item read) or a new index, backfilled across every item. Many teams end up using both: PostgreSQL as the system of record, DynamoDB for a specific high-volume, key-based workload.

> **Case file**
>
> | | |
> |---|---|
> | **The case** | "Paid orders over 900 in March?" is quick on one database and a surprise bill on the other |
> | **Suspects** | PostgreSQL, DynamoDB |
> | **Culprit** | A question the DynamoDB keys weren't designed for becomes a full `Scan` |
> | **The fix** | PostgreSQL as the system of record, DynamoDB for known key-based workloads |
> | **Evidence** | 200,000 orders in PostgreSQL 17.11 and DynamoDB Local 3.3.2 (`make pgdyn`) |

## The case

Finance sends a one-line message: "how many paid orders over 900 did we have in March?" On one database that's a quick query. On the other it's a surprise on the bill. Which one, and why?

Both suspects are excellent databases, built on different bets. PostgreSQL bets that you'll keep thinking of new questions; DynamoDB bets that you already know them. This case watches those two bets play out on the same data.

I loaded the same 200,000 orders into PostgreSQL and into a DynamoDB single-table design (DynamoDB Local), and ran the query both were designed for, an ad-hoc report, and a new access pattern. The evidence is in [database-tradeoffs-lab](https://github.com/the-vishal-kumar/database-tradeoffs-lab/tree/main/14-postgres-or-dynamodb) (`make pgdyn`).

## The suspects at a glance

| | PostgreSQL (RDS, Aurora or self-run) | DynamoDB |
|---|---|---|
| **Data model** | Tables, joins, constraints | Items in partitions; you design keys around access patterns |
| **New question** | Write a query; add an index if it's frequent | Scan (pay per item read), or add a global secondary index and wait for its backfill |
| **Transactions** | Any statements, any rows | Up to 100 items per transaction; conditional writes per item |
| **Scaling** | Vertical, plus read replicas; sharding is your problem | Horizontal and automatic, by partition key |
| **Operations** | Vacuum, upgrades, connections, failover (less on RDS/Aurora) | Almost none; capacity mode, keys and hot partitions are your problem |
| **Cost model** | An instance per hour, whether busy or not | Per request (on-demand) or per provisioned capacity, plus storage |
| **Multi-tenancy** | Row-level security, schemas, or databases | Tenant in the partition key; IAM conditions on leading keys |
| **Pick it when** | The product is new, reporting matters, and data is relational | Access patterns are known and stable, scale is large or spiky, or the workload is pure key-value |

## The same data, three questions

Let's line them up on real numbers. 200,000 orders from 1,000 customers over a year. PostgreSQL has one table, with an index on `(customer_id, created_at)`. DynamoDB has one table keyed for the known pattern: partition key `CUSTOMER#id`, sort key `ORDER#timestamp#id`.

*DynamoDB Local is a Java emulator reached over HTTP, so its latencies say nothing about real DynamoDB, which answers a designed query in single-digit milliseconds. The **items read** and **read capacity units (RCU)** follow DynamoDB's documented accounting, and those carry over.*

| Question | PostgreSQL | DynamoDB: items read | DynamoDB: read capacity |
|---|---|---:|---:|
| A customer's 20 latest orders (designed for) | 0.11 ms | 20 | **0.5 RCU** |
| Paid orders over 900 in March, all customers (ad hoc) | 13 ms, no index for it | **200,000** (the whole table) | **2,689 RCU** |
| Latest orders with status "placed", all customers (added later) | 0.13 ms after a 0.26 s `CREATE INDEX` | 20, after building a GSI | 0.5 RCU |

```mermaid
xychart-beta
  title "PostgreSQL time per question"
  x-axis ["Designed for", "Ad hoc, no index", "Added later"]
  y-axis "ms"
  bar [0.11 , 13 , 0.13]
```

### 1. The designed query: both have an alibi

For the access pattern it was built for, DynamoDB read exactly the 20 items it returned, for half a read unit, and it will do that at the same speed with 200 million orders. This is what DynamoDB is for, and it's a genuinely beautiful property: the cost of the query doesn't depend on the size of the table at all. PostgreSQL did it in 0.11 ms with an ordinary index.

### 2. The question nobody planned: the real clue

Finance asks for paid orders over 900 in March. PostgreSQL has no index for that, so it planned a sequential scan and answered in 13 ms. At 200 million rows that would be slow, and you'd add an index, but you *can* ask. That freedom is what a query planner gives you.

DynamoDB has no query planner. A question that doesn't start from a partition key is a `Scan`: it read **all 200,000 items**, consumed **2,689 RCU** to return 401 of them, and the filter was applied *after* reading and paying. That's about 5,000× the cost of the designed query, and it grows linearly with the table. Every ad-hoc report, admin search, data fix and "how many customers did X?" costs that much, so DynamoDB teams export data to an analytics store (S3 + Athena, or a warehouse) to answer these questions instead. There's the surprise on the bill.

### 3. A new access pattern: easy in both, if you can wait

A product change needs "the latest orders in a given status, across customers". PostgreSQL: one `CREATE INDEX` (0.26 s here; use `CONCURRENTLY` on a live table). DynamoDB: a **global secondary index** on `(status, created)`. That's a second copy of the data that every future write also updates (more write capacity), that is only eventually consistent with the table, and that has to be **backfilled** across every existing item before it's usable. Both then answered the new question by reading only 20 items.

One more DynamoDB-specific wrinkle with this index: `status` has only five values, so all "placed" orders share one GSI partition. A popular status is a hot partition. The usual fix is to spread it with a suffix (`placed#0` … `placed#9`) and query all ten. That's the kind of design work DynamoDB moves from query time to modelling time. It's a fair trade, and an elegant one: you do the thinking once, up front, and every read after that is cheap.

```mermaid
flowchart TD
  Q1{"Are access patterns few, known and stable?"}
  Q1 -->|no| PG["PostgreSQL"]
  Q1 -->|yes| Q2{"Pure key-value, large or spiky scale?"}
  Q2 -->|no| PG
  Q2 -->|yes| DD["DynamoDB for that workload"]
  DD --> BOTH["PostgreSQL stays the system of record"]
  PG --> BOTH
```

## Use case 1: an early-stage SaaS with admin dashboards and reports

**What I'd pick:** PostgreSQL. You'll add reports, filters, admin tools and customer-specific exports every month, and each one should be a query, not a data-modelling project. A managed instance (RDS or Aurora) handles thousands of transactions per second, and row-level security gives you tenant isolation in the database (the [tenant isolation case](/p/postgres-rls-tenant-isolation)).

## Use case 2: a known, high-volume, key-based workload

**Examples:** sessions, carts, device state, idempotency keys, rate-limit counters, a feed of events per user.

**What I'd pick:** DynamoDB for that workload, next to the main database. The access pattern is "get or put by key", it never changes, traffic may spike 100×, and nobody needs to join it with anything. On-demand capacity follows it (it absorbs up to double the previous peak at once and adapts within minutes beyond that, so pre-warm or ramp before a known 100× event), there's no server to run, TTL deletes expired items for free, and latency stays flat as the table grows.

## Use case 3: multi-tenant B2B with strict isolation

**What I'd pick:** PostgreSQL with row-level security for most products; it enforces the tenant boundary in the database. DynamoDB can do it too: put the tenant in the partition key, and use IAM policy conditions (`dynamodb:LeadingKeys`) so a tenant's credentials can only touch its own partitions. That works well for pooled, key-based data, but cross-tenant reporting is then a scan or an export, every time.

## Clues people overlook

- **DynamoDB's single-table design is a commitment.** It's efficient because the keys encode today's access patterns. New ones mean GSIs (default quota: 20 per table), duplicated items, or a migration that rewrites keys.
- **DynamoDB items are capped at 400 KB**, and a query returns at most 1 MB per page. Model for both.
- **PostgreSQL's limits are operational:** connections (use a pooler; the [scaling case](/p/scale-an-api)), vacuum (the [long-transaction case](/p/long-transaction-slows-database)), and one primary for writes, until you shard.
- **Cost shapes differ.** PostgreSQL costs the same at 3 a.m. as at peak. DynamoDB on-demand costs nothing when idle and a lot under heavy scans. Price your *real* read pattern, including reports, not only the happy path.


> **Remember this**
> - PostgreSQL bets you'll think of new questions, DynamoDB bets you already know them.
> - A DynamoDB `Scan` reads and pays for every item, then filters.
> - Price your real read pattern, reports included.

## What I'd do on Monday

1. **Start with PostgreSQL** as the system of record for a new product.
2. **Add DynamoDB for specific workloads** that are key-based, high-volume or spiky, and stable: sessions, idempotency keys, event feeds, device state.
3. **If DynamoDB is the main store,** write down every access pattern before designing keys, plan the export path for reporting on day one, and treat a `Scan` in application code as a bug.
4. **Revisit when the shape is clear:** a mature product with a few huge, stable access patterns is exactly where moving a hot path to DynamoDB pays off.

The neatest resolution is often not convicting either suspect: let PostgreSQL keep answering the questions you haven't thought of, and let DynamoDB do the one job it was designed for.

*Measured Nov 2026: PostgreSQL 17.11 and DynamoDB Local 3.3.2 in Docker on one laptop, 200,000 orders. Read capacity and items read follow DynamoDB's documented accounting; latencies from DynamoDB Local are not representative of the real service. DynamoDB limits (400 KB items, 100-item transactions, 20 GSIs by default) from its documentation, Nov 2026. Code and full results: [database-tradeoffs-lab/14-postgres-or-dynamodb](https://github.com/the-vishal-kumar/database-tradeoffs-lab/tree/main/14-postgres-or-dynamodb).*
