Difficulty: Intermediate
When would you choose Amazon RDS over DynamoDB, and when is DynamoDB the better fit?
Choose RDS (or Aurora) when your data is relational and your queries are not fully known in advance: joins, ad-hoc reporting, multi-table transactions, and strong SQL constraints. Choose DynamoDB when you know your access patterns up front and need predictable single-digit millisecond reads and writes at any scale, with no servers or connection pools to manage. The decision is mostly about access patterns, not about "SQL is old, NoSQL is modern".
RDS runs a managed relational engine (PostgreSQL, MySQL, MariaDB, Oracle, SQL Server, Db2) on an instance you size. AWS handles backups, patching, Multi-AZ failover, and read replicas, but you still pick an instance class, and scaling writes means a bigger instance.
DynamoDB is a serverless key-value and document store. Every item has a partition key (and optionally a sort key). DynamoDB hashes the partition key to spread data across many partitions, which is why it scales horizontally almost without limit. You query by key, or by a Global Secondary Index (GSI) you defined in advance. There are no joins.
| Aspect | RDS | DynamoDB |
|---|---|---|
| Data model | Tables, foreign keys, normalised | Items in a table, often single-table design |
| Queries | Any SQL, joins, aggregations | Get/Query by key or index; Scan is expensive |
| Scaling | Vertical for writes, read replicas for reads | Horizontal, automatic partitioning |
| Transactions | Full ACID across any rows | ACID transactions up to 100 items |
| Capacity | Pay per instance hour + storage | On-demand (per request) or provisioned RCU/WCU |
| Item/row limits | Large rows fine | Max item size 400 KB |
| Connections | Connection limits; use RDS Proxy with Lambda | HTTP API, no connection pooling issues |
JOIN across orders, users, products, and coupons, plus finance reports nobody has designed yet.status or today's date sends most traffic to one partition. Use high-cardinality keys like userId or orderId.A common real-world answer is "both": an RDS/Aurora database as the system of record, and DynamoDB for a high-traffic slice like carts or idempotency keys for payment requests.
import boto3
from boto3.dynamodb.conditions import Key
# RDS (PostgreSQL): flexible, joins are fine
sql = """
SELECT o.id, o.total_paise, u.name
FROM orders o JOIN users u ON u.id = o.user_id
WHERE o.user_id = %s ORDER BY o.created_at DESC LIMIT 10;
"""
# DynamoDB: PK = USER#<id>, SK = ORDER#<timestamp>
table = boto3.resource("dynamodb").Table("shop")
resp = table.query(
KeyConditionExpression=Key("PK").eq("USER#42") & Key("SK").begins_with("ORDER#"),
ScanIndexForward=False, # newest first
Limit=10,
)
print(resp["Items"])
In DynamoDB the 'last 10 orders for a user' pattern is baked into the key design, so it is a single fast Query. In SQL the same result comes from a join that needs no upfront design.
Amazon RDS, DynamoDB, Access Patterns, Partition Key, Capacity Modes