Overview and What You Will Learn
AWS takes a purpose-built approach to databases: instead of one relational engine for every job, you match each workload's data model and access pattern to an engine designed for it. The fastest way to choose is to ask what your most important query looks like: a key lookup, a SQL join, a text search, a graph traversal, an aggregation over billions of rows, or a metric over a time range.
In this guide you will learn:
- When to use RDS and Aurora for relational data with joins and ACID transactions
- When DynamoDB fits, and why it demands that you know your access patterns first
- When DocumentDB, Keyspaces, and Neptune are better than a general-purpose store
- Why Amazon Timestream for LiveAnalytics is closed to new customers and what to use instead
- How Redshift, ElastiCache, and OpenSearch Service handle analytics, caching, and search
- A two-step decision framework you can apply to any new workload
You will also run a short lab that shows how a DynamoDB table behaves for key, index, and scan access, and how a relational join differs.
Why This Matters in Production
A relational database asked to do session lookups, text search, and analytics at the same time is mediocre at all three. A mismatched database shows up as slow queries, runaway cost, or a painful migration after launch. A typical food-delivery platform like Swiggy splits its data on purpose: orders in a relational store, catalogue and sessions in a key-value store, hot reads in a cache, and restaurant search in a search engine. Choosing early is cheaper because moving a data model later means migrating data and rewriting queries.
Core Principles
Pick the engine that matches the access pattern, not the one your team already knows. Start with the specialised engines, because their query shapes are the most distinctive.
If none of those apply, you are choosing a general-purpose store. Migration constraints come first, then the shape of your reads.
If you reach the end without a clear match, you almost certainly need RDS or Aurora.
When to Use RDS or Aurora
Use RDS or Aurora when your data is relational, your queries need joins, and your transactions must be ACID. RDS runs managed PostgreSQL, MySQL, MariaDB, Oracle, SQL Server, and Db2. Aurora is AWS's cloud-native MySQL and PostgreSQL compatible engine, which stores six copies of your data across three Availability Zones and, per AWS, delivers up to 5x the throughput of standard MySQL and 3x that of standard PostgreSQL. Aurora Serverless v2 adjusts capacity for variable load.
- Good fit: trading ledgers, payment settlement, order management, anything where a missing row breaks a business rule
- Avoid when: you need millions of simple key lookups per second, frequently changing schemas, or full-text relevance search
When to Use DynamoDB
Use DynamoDB when you access items by key at very high scale and need single-digit millisecond latency without managing servers. It is serverless, offers on-demand capacity, TTL for automatic expiry, streams for change events, and global tables for multi-Region active-active writes. The trade-off is that you design the table around your queries up front.
- Good fit: user sessions, shopping carts, reward balances, short-lived transaction state with TTL
- Avoid when: you need ad hoc queries on arbitrary attributes, multi-table joins, or relational integrity
When to Use DocumentDB
Use DocumentDB when your data is nested JSON with a flexible schema and you want MongoDB-compatible drivers and queries. It implements the MongoDB API on AWS-built storage, so check feature compatibility before you migrate an existing application.
- Good fit: product catalogues where each product has different attributes, content and profile stores
- Avoid when: you only need key-value access (DynamoDB is simpler and cheaper) or you rely on joins
When to Use Neptune
Use Neptune when relationships between entities are the main thing you query. Graph traversals such as "accounts within three hops of a known fraudulent account" stay efficient as depth grows, where SQL joins slow down. Neptune supports Gremlin, openCypher, and SPARQL, and Neptune Analytics covers large-scale graph analytics.
- Good fit: fraud detection, social graphs, knowledge graphs, recommendation paths
- Avoid when: your queries are mostly lookups or aggregations rather than traversals
When to Use Keyspaces
Use Amazon Keyspaces when you already run Apache Cassandra and want a serverless, CQL-compatible service without managing clusters. For a brand-new AWS-native NoSQL workload, DynamoDB is usually the simpler choice.
When to Use Timestream for InfluxDB
Use a time-series database when data arrives as timestamped measurements and queries aggregate over time ranges, such as IoT sensors, application metrics, or tick data. Amazon Timestream for LiveAnalytics closed to new customers on June 20, 2025, so new projects should evaluate Amazon Timestream for InfluxDB, a managed InfluxDB service that runs in your VPC and is billed per instance. Aurora PostgreSQL with time partitioning is another option when you want to stay relational.
- Good fit: sensor readings, p99 latency over 7 days, daily closing prices
- Avoid when: you need rich joins across entities or transactional updates
When to Use Redshift
Use Redshift for analytical queries (OLAP) that scan and aggregate very large datasets. It stores data by column and runs in provisioned or serverless form, and Redshift Spectrum can query data in S3 without loading it first.
- OLTP engines (RDS, DynamoDB) handle many small transactions touching few rows
- OLAP engines (Redshift) handle few large queries touching millions of rows
- For ad hoc SQL over S3 with no warehouse to run, also consider Amazon Athena
When to Use ElastiCache
Use ElastiCache as an in-memory layer in front of another database to get sub-millisecond reads and to offload repeated queries. It is a cache, not a system of record. Choose the Valkey or Redis OSS engines for replication, persistence options, Multi-AZ failover, and rich data types, and Memcached only for a simple multi-threaded cache. If you need Redis-compatible data that is durable as a primary store, look at Amazon MemoryDB.
When to Use OpenSearch Service
Use Amazon OpenSearch Service for full-text search, log analytics, and near-real-time dashboards. Every field is indexed, results are ranked by relevance, and typos and filters are handled for you. A SQL query like LIKE '%biryani%' cannot use a normal index and degrades badly on millions of rows. Visualise data with OpenSearch Dashboards, and do not use OpenSearch as your only copy of important data.
Quick Comparison
| If your main need is | Choose |
|---|---|
| SQL, joins, ACID transactions | RDS or Aurora |
| Key access at massive scale | DynamoDB |
| JSON documents, MongoDB migration | DocumentDB |
| Relationship traversal | Neptune |
| Cassandra migration | Keyspaces |
| Time-series metrics | Timestream for InfluxDB |
| Analytics on billions of rows | Redshift |
| Sub-millisecond cached reads | ElastiCache |
| Full-text search and log analytics | OpenSearch Service |
Detailed Step-by-Step Practical Lab
This lab creates one on-demand DynamoDB table (pennies of cost), shows how access pattern changes behaviour, and contrasts it with a relational join using SQLite as a stand-in for RDS. You need the AWS CLI configured, Terraform 1.6 or later, and Python 3.12 with boto3 installed.
Step 1: Create a DynamoDB Table with a Secondary Index and TTL
terraform { required_version = ">= 1.6.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 6.0" } }} provider "aws" { region = "ap-south-1"} resource "aws_dynamodb_table" "sessions" { name = "hotstar-sessions-lab" billing_mode = "PAY_PER_REQUEST" # on-demand: no capacity planning hash_key = "session_id" # partition key: the main access path attribute { name = "session_id" type = "S" } attribute { name = "user_id" type = "S" } # Second access path: find all sessions for one user global_secondary_index { name = "user-index" hash_key = "user_id" projection_type = "ALL" } # Items disappear automatically after expires_at (epoch seconds) ttl { attribute_name = "expires_at" enabled = true } tags = { Purpose = "database-selection-lab" }}terraform initterraform applyStep 2: Compare Key, Index, and Scan Access
Save this as dynamo_patterns.py and run it. It loads 400 sessions, then reads them three ways.
import time import boto3from boto3.dynamodb.conditions import Attr, Key table = boto3.resource("dynamodb", region_name="ap-south-1").Table("hotstar-sessions-lab")cities = ["Mumbai", "Chennai", "Delhi", "Kolkata"]now = int(time.time()) # Load 400 sessions across 100 userswith table.batch_writer() as batch: for i in range(400): batch.put_item( Item=dict( session_id=f"sess-{i:04d}", user_id=f"user-{i % 100:03d}", city=cities[i % 4], expires_at=now + 3600, ) ) # Access pattern 1: get one item by its key (fast, cheap, one item read)item = table.get_item(Key=dict(session_id="sess-0042"))["Item"]print("get_item ->", item["user_id"], item["city"]) # Access pattern 2: query the secondary index (reads only that user's items)time.sleep(2) # the index is eventually consistentresp = table.query(IndexName="user-index", KeyConditionExpression=Key("user_id").eq("user-007"))print("query -> returned", resp["Count"], "scanned", resp["ScannedCount"]) # Access pattern 3: filter on an attribute with no index (must read everything)resp = table.scan(FilterExpression=Attr("city").eq("Mumbai"))print("scan -> returned", resp["Count"], "scanned", resp["ScannedCount"])get_item -> user-042 Kolkataquery -> returned 4 scanned 4scan -> returned 100 scanned 400The query read only the 4 matching items. The scan read all 400 items to return 100, and you pay for every item it reads. On a table with 400 million items that difference is the whole bill.
Step 3: See What a Relational Join Does Instead
The same business question, "revenue by city", is one declarative query when the data is relational. Save as relational_join.py.
import sqlite3 db = sqlite3.connect(":memory:")db.executescript("""CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, city TEXT);CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(id), amount INTEGER);INSERT INTO customers VALUES (1, 'Rahul', 'Mumbai'), (2, 'Priya', 'Chennai');INSERT INTO orders VALUES (1, 1, 450), (2, 1, 300), (3, 2, 820);""") # Any combination of attributes works without redesigning the tables firstrows = db.execute("""SELECT c.city, COUNT(*) AS orders, SUM(o.amount) AS revenueFROM orders o JOIN customers c ON c.id = o.customer_idGROUP BY c.city""").fetchall() for city, orders, revenue in rows: print(city, orders, revenue)In DynamoDB you would have to model the data for this exact question in advance. That is the trade-off: DynamoDB gives predictable speed for known patterns, and a relational engine gives flexibility for questions you have not asked yet.
Step 4: Practise the Decision Framework
Save as pick_database.py and answer for a real workload you own.
# Ordered rules: the first "yes" wins, mirroring the decision diagramsRULES = [ ("Do you need full-text search or log analytics?", "Amazon OpenSearch Service"), ("Is the data metrics or events indexed by time?", "Amazon Timestream for InfluxDB"), ("Are you running analytics over billions of rows?", "Amazon Redshift"), ("Do you need sub-millisecond reads in front of another store?", "Amazon ElastiCache"), ("Are relationships between entities the main query?", "Amazon Neptune"), ("Are you migrating an existing MongoDB application?", "Amazon DocumentDB"), ("Are you migrating an existing Cassandra application?", "Amazon Keyspaces"), ("Is access mostly by key at very high scale?", "Amazon DynamoDB"),] for question, service in RULES: if input(f"{question} (y/n) ").strip().lower() == "y": print(f"Start with: {service}") breakelse: print("Start with: Amazon RDS or Aurora")python3 pick_database.pyStep 5: Clean Up
terraform destroyProduction Best Practices & Common Pitfalls
Common MistakeUsing RDS for everything out of familiarity. Relational engines are excellent for relational data, but they are inefficient for huge key-value workloads, full-text search, time-series metrics, and warehouse-scale analytics.
Common MistakeUsing DynamoDB for data with many relationships, then relying on Scan. If you frequently join users to orders to products to reviews, the access pattern fits a relational engine. Single-table design can cover some of it, but at a real complexity cost.
RememberElastiCache is a cache. Use the cache-aside pattern: read from the cache first, fall back to the database on a miss, then write the result back with a TTL. Never treat cached data as the only copy.
TipMost production systems use more than one database on purpose. Pairing Aurora for orders, DynamoDB for catalogue and sessions, ElastiCache for hot reads, and OpenSearch for search lets each engine do what it is best at. Move data between them with DMS, DynamoDB Streams, or event pipelines instead of dual-writing from the application.
SecurityWhatever you choose, keep databases in private subnets, encrypt at rest with KMS, require TLS, and grant access through IAM and Secrets Manager instead of hard-coded credentials.
- Write down your top five queries first. The access pattern decides the engine, so list the queries, their frequency, and their latency target before choosing.
- Prefer managed and serverless options to start. On-demand DynamoDB, Aurora Serverless v2, and Redshift Serverless remove capacity planning while you learn real traffic.
- Check service availability before committing. Some services close to new customers or lack features in certain Regions, as Timestream for LiveAnalytics did.
- Plan for data movement. Decide how data flows between stores before launch, because that is where polyglot systems usually break.
- TTL deletion is not instant. DynamoDB removes expired items in the background, so filter on the expiry time in queries that must never see stale items.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
aws dynamodb describe-table --table-name NAME |
Show keys, indexes, and capacity mode |
aws rds describe-db-instances |
List RDS instances and engines |
aws rds describe-db-clusters |
List Aurora clusters |
aws docdb describe-db-clusters |
List DocumentDB clusters |
aws elasticache describe-replication-groups |
List cache clusters |
aws opensearch list-domain-names |
List OpenSearch domains |
aws redshift-serverless list-workgroups |
List Redshift Serverless workgroups |
aws timestream-influxdb list-db-instances |
List Timestream for InfluxDB instances |
| Symptom | Fix |
|---|---|
| DynamoDB throttling on one key | Choose a higher-cardinality partition key or spread writes |
| Scan is slow and expensive | Add a secondary index or redesign the key for the query |
| RDS "too many connections" from Lambda | Put RDS Proxy between Lambda and the database |
| Low cache hit rate | Review key design, TTLs, and cache size |
| Redshift queries are slow | Review sort and distribution keys and concurrency settings |
| OpenSearch cluster status yellow | Check replica shards and available nodes |