How do you choose between RDS/Aurora, DynamoDB and ElastiCache? How do you design DynamoDB keys?
RDS and Aurora (relational)
- RDS: managed PostgreSQL, MySQL, Oracle, SQL Server, MariaDB; Multi-AZ standby for failover; read replicas.
- Aurora: AWS's cloud-native storage layer (six copies across three AZs), faster failover (typically under 30 s), up to 15 low-lag replicas, Global Database for cross-region DR, Serverless v2 for variable load.
- Choose for relational data, complex queries and joins, transactions across entities, and when the access patterns are not fully known. Scale reads with replicas and RDS Proxy (connection pooling, important for Lambda); writes scale vertically or by sharding.
DynamoDB (key-value / document)
- Serverless, single-digit-millisecond latency at virtually any scale, on-demand or provisioned capacity, global tables (multi-region active-active), streams, TTL, transactions (up to 100 items).
- Requires designing for known access patterns up front; no joins, limited ad hoc querying.
- Choose for high-scale, simple access patterns: sessions, carts, user profiles, IoT, idempotency keys, leaderboards.
ElastiCache (Redis/Valkey or Memcached)
In-memory cache and data structures: caching, sessions, rate limiting, leaderboards (sorted sets), pub/sub, distributed locks with care. Not the system of record unless you accept its durability model.
DynamoDB key design
- Partition key determines the physical partition; choose a high-cardinality, evenly accessed key (
customerId,orderId), never something likestatusordate. - Sort key enables range queries and hierarchical data within a partition:
PK = CUSTOMER#42,SK = ORDER#2026-10-31#9f1. - Single-table design: store several entity types in one table with generic
PK/SKattributes so related items can be fetched in one query. - GSIs for alternative access patterns (look up orders by status and date), with their own capacity.
- Each partition supports about 3,000 RCU and 1,000 WCU; adaptive capacity helps, but hot keys still throttle.
Example
Access patterns Key design
Get customer profile PK=CUSTOMER#42 SK=PROFILE
List a customer's orders, newest first PK=CUSTOMER#42 SK begins_with ORDER# (ScanIndexForward=false)
Get one order with its items PK=ORDER#9f1 SK=ORDER | ITEM#1 | ITEM#2
Orders by status for operations GSI1: PK=STATUS#SHIPPED SK=2026-10-31T10:00Z#9f1Follow-up questions interviewers ask
Try answering each one before you open it.
How do you fix a hot partition in DynamoDB?
Identify it with CloudWatch Contributor Insights. Spread writes with write sharding (append a random or calculated suffix 0–N to the key and query all shards on read), cache hot reads with DAX or ElastiCache, redesign the key for better cardinality, and batch or buffer bursty writes through SQS.
Aurora read replicas: what consistency do readers get?
Replicas share the same storage volume, so lag is typically under 100 ms but not zero; readers can see slightly stale data. Route read-your-own-write paths to the writer endpoint and only lag-tolerant queries to the reader endpoint. Spring's AbstractRoutingDataSource with @Transactional(readOnly = true) routing is a common pattern.