Choosing a Database on AWS

System Design · Scaling & Data · Intermediate · 18 min

Pick the right AWS database (RDS, Aurora, DynamoDB, ElastiCache, DocumentDB, Neptune, OpenSearch, Redshift, Timestream) from the access pattern, consistency need and scale.

A hardware store wall of tools. You don't ask 'which tool is best?'. You look at the job (a screw, a nail, a pipe) and the right tool is obvious.

The idea in everyday words

Choosing a database is like choosing a vehicle. A scooter (cache) is fastest across town but carries almost nothing. A delivery van (relational DB) carries anything in neat boxes with a checklist. A freight train (data warehouse) moves enormous loads but only on fixed tracks and schedules. Nobody asks 'what is the best vehicle?'; they ask 'what am I moving, how far, and how fast?'.

Start from the access pattern, not the brand

An access pattern is a question your app asks the data, again and again. "Get the cart for user 42." "Show this month's revenue by region." "Find products matching 'blu sneekers'."

Key idea: the shape of your questions picks the database, not the other way round. Write down these four facts first:

Fact Ask yourself Example answers
Access pattern How do I read it? by key, by SQL query, by text, by relationship, by big scan
Latency How fast must it answer? under 1 ms, a few ms, seconds is fine
Consistency Must every read see the latest write? yes for money, "a second stale is OK" for likes
Scale How much data and traffic? 30 staff, or 10 million shoppers

Latency = waiting time for one answer. Throughput = how many answers per second. Consistency = whether readers always see the newest data.

Tiny example: a shopping cart. Read by user id (key), a few ms is fine, slightly stale is OK, 10M users. That screams key-value at scale: DynamoDB.

The AWS database menu

Service Data model Great for Not for
Amazon RDS Relational (Postgres, MySQL, MariaDB, SQL Server, Oracle, Db2) classic apps, joins, transactions huge write scale
Amazon Aurora Relational, MySQL / PostgreSQL compatible high-traffic SQL, fast failover, many read replicas tiny always-on apps on a tight budget (Serverless v2 can help, see below)
Amazon DynamoDB Key-value and document, serverless carts, profiles, sessions at any scale ad-hoc queries and joins
Amazon ElastiCache In-memory (Valkey, Redis OSS, Memcached) caching, sessions, leaderboards, rate limits the only copy of important data
Amazon DocumentDB JSON documents, MongoDB compatible moving a MongoDB app to AWS heavy relational joins
Amazon Neptune Graph (Gremlin, openCypher, SPARQL) fraud rings, social graphs, recommendations simple key lookups
Amazon OpenSearch Service Search index full-text search, log analytics the system of record
Amazon Redshift Columnar data warehouse BI dashboards, big aggregates per-request app writes
Amazon Timestream for InfluxDB Time series metrics, IoT readings general app data

A few more you will hear about: Aurora Serverless v2 (Aurora that scales capacity up and down, and on supported versions can auto-pause to 0 ACUs when idle, so a quiet dev or small app pays mostly for storage; the trade-off is a resume delay of several seconds on the first request; see the Aurora Serverless v2 docs), Aurora DSQL (a newer serverless, distributed SQL option), MemoryDB (Redis/Valkey compatible but durable), Amazon Keyspaces (Cassandra compatible) and Athena (SQL directly on files in S3). For Timestream: the original engine (Timestream for LiveAnalytics) is closed to new customers, so new projects use Timestream for InfluxDB; check the AWS docs for the current status.

Two in-memory options people mix up:

  • DynamoDB Accelerator (DAX) is a read-through / write-through cache that sits in front of DynamoDB and speaks the DynamoDB API. If DynamoDB is already your source of truth, DAX gives microsecond reads with no cache logic in your app. It serves eventually consistent reads; strongly consistent reads pass through to DynamoDB.
  • MemoryDB is a durable, Redis/Valkey compatible database (writes go to a multi-AZ transaction log). Use it when you want in-memory speed AND it is the primary copy. ElastiCache is a cache: assume you can lose it.

Columnar means each column is stored together, so "sum of revenue" reads only the revenue column, not whole rows.

A decision guide you can say out loud

Walk these questions in order and stop at the first "yes":

  1. Key lookups that must answer in under 1 ms? → ElastiCache in front of a durable store (or DAX if that store is DynamoDB, or MemoryDB if the in-memory copy must be durable).
  2. Are the relationships the data (friends of friends, shared devices)? → Neptune.
  3. Full-text / fuzzy search with ranking? → OpenSearch.
  4. Big scans and aggregates over history? → Redshift (or Athena on S3).
  5. Nonstop timestamped measurements? → Timestream.
  6. Flexible JSON documents? → DocumentDB if you need the MongoDB API, else DynamoDB.
  7. Get/put by a known key at any scale? → DynamoDB.
  8. Joins, transactions, ad-hoc SQL? → Aurora for large or growing load, RDS for small and simple.

Why this order? The most specialised needs go first. A general database can fake search or graphs, but badly, so a specialised need must win before a general store swallows it. The cache goes first of all because only memory reaches microseconds (ElastiCache, DAX or MemoryDB, depending on what sits behind it).

Consistency check after you pick: DynamoDB reads are eventually consistent by default; ask for strongly consistent reads when you must see the latest write. Aurora and RDS read replicas lag a little behind the writer; read from the writer when you need fresh data. DynamoDB also supports transactions, but across a limited number of items and without joins.

One app, several databases (polyglot persistence)

Real systems mix databases. An online shop might use:

Feature Store Why
Orders and payments Aurora PostgreSQL money needs ACID transactions and joins
Shopping carts DynamoDB key lookups for millions of users
Login sessions ElastiCache (Valkey) checked on every request, must be sub-ms
Product search OpenSearch typo tolerance and ranking
Sales dashboards Redshift scans years of data

They stay in sync through events, not by the app writing to five places: DynamoDB Streams or an outbox table feed Lambda functions, and zero-ETL integrations (for example Aurora to Redshift) copy data for analytics.

The trade-off: every extra database is another thing to secure, back up, monitor and pay for. Start with as few as you can (often Aurora or DynamoDB plus a cache) and add one only when an access pattern truly needs it.

What the calls look like with boto3 (real AWS SDK, runs on AWS, not in this browser):

import boto3
ddb = boto3.resource("dynamodb").Table("Carts")
cart = ddb.get_item(Key={"user_id": "42"}).get("Item")

# Strongly consistent read when you must see the latest write
cart = ddb.get_item(Key={"user_id": "42"}, ConsistentRead=True)["Item"]

Other clouds: GCP uses Cloud SQL / AlloyDB / Spanner, Firestore / Bigtable, Memorystore and BigQuery; Azure uses Azure SQL / Azure Database for PostgreSQL, Cosmos DB, Azure Managed Redis (Azure Cache for Redis is being retired) and Microsoft Fabric (which absorbs Synapse); open source: PostgreSQL, MySQL, MongoDB, Valkey/Redis, Neo4j, OpenSearch, ClickHouse, InfluxDB.

Step by step

  1. List the features:

    Shop app: orders, carts, sessions, search, dashboards. Each feature is a separate access pattern.

  2. Sessions:

    Checked on every request, key = token, needs < 1 ms. Rule 1 matches → ElastiCache. (If sessions already lived in DynamoDB, DAX in front of it would be the other natural answer.)

  3. Search:

    Users type 'blu sneekers'. Not sub-ms, not a graph, but full-text with typos. Rule 3 matches → OpenSearch.

  4. Dashboards:

    Revenue by month over 3 years = huge scans. Rule 4 → Redshift. Data arrives from Aurora by zero-ETL.

  5. Carts:

    Get/put by user id, 10M users, a few ms is fine. Rules 1-6 say no, rule 7 → DynamoDB.

  6. Orders:

    Orders, payments, refunds with joins and transactions, high traffic. Rule 8 with scale 'large' → Aurora.

  7. Sanity check:

    Five stores is a lot. Could carts live in Aurora at first? Yes, if traffic is modest. Add DynamoDB when the key-value load justifies it.

Code example

# Polyglot persistence: pick a store per feature of one shop app.
RULES = [
    ("ElastiCache", lambda n: n["pattern"] == "key-value" and n["latency"] == "sub-ms"),
    ("Neptune",     lambda n: n["pattern"] == "graph"),
    ("OpenSearch",  lambda n: n["pattern"] == "search"),
    ("Redshift",    lambda n: n["pattern"] == "analytics"),
    ("DynamoDB",    lambda n: n["pattern"] == "key-value"),
    ("Aurora",      lambda n: n["pattern"] == "relational"),
]

features = {
    "sessions":   {"pattern": "key-value", "latency": "sub-ms"},
    "carts":      {"pattern": "key-value", "latency": "ms"},
    "orders":     {"pattern": "relational", "latency": "ms"},
    "search":     {"pattern": "search", "latency": "ms"},
    "dashboards": {"pattern": "analytics", "latency": "seconds"},
}

for name, need in features.items():
    for service, rule in RULES:
        if rule(need):
            print(f"{name:<11}-> {service}")
            break

Interview tips

  • Always say the access pattern before the product: 'Carts are read by user id at high scale, so DynamoDB; orders need transactions, so Aurora.'

  • Name the source of truth and the copies: 'OpenSearch is fed from Aurora via a stream; if it is lost we rebuild it.'

  • Mention consistency: DynamoDB is eventually consistent by default with an opt-in strongly consistent read; replicas lag the writer.

  • Show cost awareness without numbers: 'DynamoDB on-demand for spiky traffic; check the AWS pricing page before committing.'

  • Other clouds: GCP Spanner / Firestore / Bigtable / BigQuery, Azure Cosmos DB / Azure SQL / Microsoft Fabric.

Challenge: Rule-Based Database Picker

Write pick_database(need). need is a dict with pattern, latency ("sub-ms" | "ms" | "seconds"), scale ("small" | "large" | "massive") and an optional boolean mongo.

Check these rules in order and return the first match:

  1. pattern "key-value" and latency "sub-ms" → "ElastiCache"
  2. pattern "graph" → "Neptune"
  3. pattern "search" → "OpenSearch"
  4. pattern "analytics" → "Redshift"
  5. pattern "time-series" → "Timestream"
  6. pattern "document" → "DocumentDB" if mongo is true, else "DynamoDB"
  7. pattern "key-value" → "DynamoDB"
  8. pattern "relational" → "Aurora" unless scale is "small", then "RDS"
  9. anything else → "Unknown"

Example: pick_database({"pattern": "key-value", "latency": "ms", "scale": "massive"}) → "DynamoDB"

Solve it in the browser with tests, hints and an AI coach.

Practice problems

More in Scaling & Data

Previous: Databases: SQL, NoSQL, Sharding · Next: DynamoDB Data Modeling