RDS vs. DynamoDB

Difficulty: Intermediate

Question

When would you choose Amazon RDS over DynamoDB, and when is DynamoDB the better fit?

Answer

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".

How each one stores and serves data

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.

Comparison

AspectRDSDynamoDB
Data modelTables, foreign keys, normalisedItems in a table, often single-table design
QueriesAny SQL, joins, aggregationsGet/Query by key or index; Scan is expensive
ScalingVertical for writes, read replicas for readsHorizontal, automatic partitioning
TransactionsFull ACID across any rowsACID transactions up to 100 items
CapacityPay per instance hour + storageOn-demand (per request) or provisioned RCU/WCU
Item/row limitsLarge rows fineMax item size 400 KB
ConnectionsConnection limits; use RDS Proxy with LambdaHTTP API, no connection pooling issues

When RDS is the right call

  • An e-commerce order system where you need JOIN across orders, users, products, and coupons, plus finance reports nobody has designed yet.
  • Strict integrity: foreign keys, unique constraints, check constraints.
  • Teams that already know SQL and need to move fast while the schema is still changing.

When DynamoDB is the right call

  • Very high, spiky traffic with simple lookups: shopping carts, session stores, user preferences, leaderboards, IoT device state.
  • Serverless apps on Lambda, where opening thousands of database connections would overwhelm a relational engine.
  • Global apps that need multi-Region active-active writes (Global Tables).

Common mistakes

  • Designing DynamoDB like SQL. If you put each entity in its own table and then need joins, you end up doing them in application code with many round trips. Model the access patterns first.
  • Hot partitions. A partition key like status or today's date sends most traffic to one partition. Use high-cardinality keys like userId or orderId.
  • Using Scan for queries. Scan reads the whole table and is billed accordingly.
  • Picking RDS for a Lambda-heavy app without RDS Proxy, then hitting "too many connections" during a traffic spike.

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.

Code examples

Same lookup in SQL and in DynamoDB

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.

Key points

  • Decide by access patterns: unknown or relational queries favour RDS, known key-based patterns at scale favour DynamoDB
  • DynamoDB has no joins, a 400 KB item limit, and transactions up to 100 items
  • RDS scales writes vertically; DynamoDB scales horizontally by partition key
  • Pick high-cardinality partition keys to avoid hot partitions
  • Lambda plus RDS usually needs RDS Proxy to manage connections

Common follow-up questions

  • How would you model a one-to-many relationship in DynamoDB without joins?
  • What is the difference between on-demand and provisioned capacity in DynamoDB?
  • What is a hot partition and how do you avoid it?
  • When would you pick Aurora instead of plain RDS?

Interview tips

  • Frame the answer around access patterns and consistency needs, not hype about NoSQL
  • Give one concrete example for each (orders and reporting for RDS, carts or sessions for DynamoDB)
  • Mentioning single-table design, GSIs, and RDS Proxy shows you have actually built with both

Concepts covered

Amazon RDS, DynamoDB, Access Patterns, Partition Key, Capacity Modes

More AWS & Cloud Fundamentals questions