Caching and Purpose-Built Databases: ElastiCache, MemoryDB, Redshift, DocumentDB, Neptune and Choosing the Right Database
One Size Does Not Fit All
AWS offers purpose-built databases. Picking the right one is a core solutions architect skill. Think about data shape, access pattern, scale, latency and consistency.
Amazon ElastiCache
ElastiCache is a managed in-memory cache (Redis OSS / Valkey and Memcached). It sits in front of a database or serves as a fast data store, giving sub-millisecond reads and reducing load on the database.
| Redis (Valkey) engine | Memcached |
| Data types | Strings, hashes, lists, sets, sorted sets, streams, geospatial | Simple key-value |
| Persistence | Yes (snapshots, AOF) | No |
| Replication and Multi-AZ failover | Yes (replicas and automatic failover) | No (data lost on node failure) |
| Backup and restore | Yes | No |
| Sharding | Cluster mode (shards) | Multi-threaded, scale by adding nodes |
| Extras | Pub/sub, Lua, transactions, Redis AUTH/TLS/IAM, leaderboards | Simple, very fast, easy horizontal scale |
Quick choice: Need persistence, replication, complex types or leaderboards → Redis. Just a simple big cache with multi-threading → Memcached.
Caching Strategies
| Strategy | How | Pros and cons |
| Lazy loading (cache-aside) | App checks cache; on miss reads the DB and writes to cache | Only requested data is cached; but first read is slow and data can be stale |
| Write-through | App writes to cache and DB together | Data in cache is fresh; but wasted memory for data never read and slower writes |
| TTL | Expire entries after a time | Controls staleness. Combine with the others |
python
import json, redis
r = redis.Redis(host="shop-cache.xxxx.cache.amazonaws.com", port=6379, ssl=True)
def get_product(pid, db):
key = f"product:{pid}"
cached = r.get(key)
if cached: # cache hit
return json.loads(cached)
row = db.fetch_product(pid) # cache miss: read the database
r.setex(key, 300, json.dumps(row)) # store for 5 minutes (TTL)
return row
- Common uses: session store (keeps web servers stateless), leaderboards, rate limiting, database query caching, real-time analytics
- Place in private subnets; security group allows only the app tier
- Use replicas in multiple AZs with automatic failover for Redis; enable encryption in transit and at rest
- ElastiCache Serverless removes node sizing
Amazon MemoryDB
- A Redis-compatible, durable, primary in-memory database: data is stored in a multi-AZ transaction log, so it survives failures without a separate database
- Use when you need microsecond reads and single-digit millisecond writes AND durability (not just a cache)
Amazon Redshift: Data Warehouse
Redshift is a managed columnar, massively parallel (MPP) data warehouse for analytics (OLAP) on terabytes to petabytes using standard SQL. Not for high-volume small transactions (OLTP).
| Feature | Details |
| Architecture | Leader node plans queries; compute nodes store data in columns and run in parallel. RA3 nodes separate compute from managed storage |
| Redshift Serverless | No clusters to manage; pay per use (RPU-seconds) |
| Redshift Spectrum | Query data in S3 directly without loading it |
| Concurrency scaling | Adds capacity automatically for bursts of queries |
| Data sharing | Share live data between clusters without copying |
| Loading | COPY from S3 (fast, parallel), Kinesis Firehose, zero-ETL from Aurora/RDS, DMS |
| Availability and DR | Multi-AZ (RA3), snapshots copied across Regions, automated snapshots |
| Security | VPC, KMS encryption, IAM, column-level security, audit logging |
sql
COPY sales FROM 's3://acme-lake/sales/2026/11/' IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftCopy' FORMAT AS PARQUET;
SELECT region, date_trunc('month', sale_date) AS month, SUM(amount) AS revenue
FROM sales GROUP BY 1, 2 ORDER BY 2, 3 DESC;
Amazon DocumentDB, Neptune, Keyspaces, Timestream
| Service | Type | Use for |
| DocumentDB (MongoDB compatible) | Document database. Storage replicated 6 ways across 3 AZs like Aurora | JSON documents, content management, catalogs, MongoDB migrations |
| Neptune | Graph database (Gremlin, openCypher, SPARQL) | Social networks, fraud detection, recommendation, knowledge graphs |
| Keyspaces (for Apache Cassandra) | Wide-column, serverless | Cassandra workloads without managing clusters |
| Timestream | Time-series database | IoT sensor data, DevOps metrics, telemetry |
| Amazon OpenSearch Service | Search and log analytics engine | Full-text search, log analytics, dashboards |
| QLDB (ledger) | Immutable ledger | AWS has announced end of support for QLDB. Plan migration to Aurora PostgreSQL for new work. Check current status |
Choosing a Database
| Requirement | Pick |
| Relational, transactions, SQL joins | RDS / Aurora |
| Key-value or document at massive scale with millisecond latency, serverless | DynamoDB |
| Cache and sessions, leaderboards | ElastiCache (Redis) |
| Durable in-memory primary database | MemoryDB |
| Analytics on large structured data, BI | Redshift |
| Ad hoc SQL on files in S3 | Athena |
| MongoDB workloads | DocumentDB |
| Relationships and graphs | Neptune |
| Cassandra workloads | Keyspaces |
| Time-series metrics | Timestream |
| Search and log analytics | OpenSearch |
| Global low-latency reads and quick regional failover (SQL) | Aurora Global Database |
| Global multi-Region active-active (NoSQL) | DynamoDB global tables |
Practice Tasks
- Add a Redis cache to a sample app and measure response time before and after
- Explain why a cache with only lazy loading can return stale data and how TTL helps
- Create a Redshift Serverless namespace, load a CSV from S3 and run a query
- For six scenarios (chat sessions, product catalog, fraud graph, IoT temperatures, monthly BI, orders), choose a database and defend it
- Compare ElastiCache Redis and MemoryDB in two sentences
Conclusion
Use caching (ElastiCache Redis or Memcached, lazy loading plus TTL) to speed reads and relieve databases, MemoryDB for durable in-memory data, Redshift for analytics, DocumentDB for MongoDB workloads, Neptune for graphs, Timestream for time series, and always choose by data shape and access pattern.
Quick Summary: ElastiCache redis vs memcached; lazy loading/write-through/TTL; MemoryDB; Redshift MPP + Spectrum; DocumentDB/Neptune/Keyspaces/Timestream/OpenSearch; decision table.