AWS Database
MemoryDB
Redis-compatible in-memory database with multi-AZ durability
Amazon MemoryDB for Redis is a Redis-compatible in-memory database with multi-AZ durability. Unlike ElastiCache which uses Redis as a cache in front of a durable database, MemoryDB stores data durably in a distributed transaction log across multiple AZs - Redis is the primary database, not just a cache. MemoryDB provides the full Redis data structure API with microsecond read latency, single-digit millisecond write latency, and strong consistency guarantees that make it suitable as a primary database rather than a caching layer.
MemoryDB vs ElastiCache Redis: The Critical Distinction
The fundamental difference is durability. ElastiCache Redis can lose data on failure even with Multi-AZ - the standby is eventually consistent. MemoryDB writes to a Multi-AZ transaction log before acknowledging a write, guaranteeing data survives node failures.
| Attribute | ElastiCache Redis | MemoryDB for Redis |
|---|---|---|
| Primary purpose | Cache in front of a durable database | Durable primary database with Redis API |
| Durability | In-memory; data may be lost on failure | Multi-AZ transaction log; survives node failures |
| Write acknowledgement | After write to primary memory | After write committed to transaction log across AZs |
| Read latency | Microseconds | Microseconds (same) |
| Write latency | Sub-millisecond | Single-digit millisecond (transaction log overhead) |
| Data loss on failure | Possible (seconds of data if replica not yet synced) | Zero (transaction log is durable) |
| Consistency | Eventual (async replication to replicas) | Strong (synchronous transaction log) |
| Cost | Lower | ~20-30% higher due to transaction log |
| Use as primary DB? | No - use with a durable backend | Yes - designed for this use case |
If you are using ElastiCache Redis as your only data store (no backing database), you should be using MemoryDB instead. ElastiCache is a cache; MemoryDB is a durable database. Using ElastiCache as a primary database risks data loss on instance failure.
Cluster Architecture: Shards, Nodes, and the Transaction Log
A MemoryDB cluster is made up of shards. Each shard has a primary node and up to 5 replica nodes. The transaction log is replicated across all AZs before a write is acknowledged.
| Component | Description | Key Detail |
|---|---|---|
| Shard | A horizontal partition of the keyspace | Up to 500 shards per cluster |
| Primary node | Handles writes and reads for the shard | One per shard |
| Replica node | Read-only copies for read scaling and failover | Up to 5 per shard; distributed across AZs |
| Transaction log | Multi-AZ durable commit log for writes | Written before primary ACKs; powered by AWS-managed service |
| Cluster endpoint | Entry point for all cluster operations | Cluster-aware client required |
MemoryDB requires a cluster-aware Redis client (most modern Redis clients support cluster mode). The keyspace is hash-slot based (16,384 slots distributed across shards), identical to Redis OSS Cluster mode.
Use Cases: When MemoryDB Is the Right Choice
| Use Case | Why MemoryDB | Alternative |
|---|---|---|
| Gaming leaderboards | Redis sorted sets with microsecond reads; durable rankings | ElastiCache + RDS (two databases to manage) |
| Session store (no backing DB) | Sessions durable without separate RDBMS | ElastiCache (risk data loss) or RDS (slower) |
| Rate limiting | Atomic Redis INCR operations; durability for billing-critical limits | ElastiCache acceptable if approximate limits OK |
| Real-time inventory / counters | Atomic operations; microsecond reads; durable counts | DynamoDB (slower) or ElastiCache (not durable) |
| Message queues (Redis Streams) | Durable streams with consumer groups | ElastiCache (stream may lose messages on failure) |
| Financial account balances | Strong consistency; durability; atomic operations | RDS (slower but full ACID) |
MemoryDB is not a replacement for PostgreSQL or DynamoDB for complex relational or document workloads. It excels at high-speed, simple data structures where microsecond access matters and durability is required. For complex queries, JOINs, or document storage, use the appropriate specialized database.
Snapshots, Security, and Redis API Compatibility
| Feature | Detail |
|---|---|
| Snapshots | Automatic daily snapshots; manual on-demand; stored in S3 managed by AWS |
| Restore | Create a new cluster from a snapshot |
| Encryption at rest | AES-256 via AWS-owned or customer KMS key |
| Encryption in transit | TLS required; cannot disable |
| Authentication | ACL-based users (username + password); IAM auth not supported |
| Redis version support | Redis 6.2 and 7.x; full ACL and module support |
| Redis modules | Limited - no third-party modules (RedisSearch, RedisGraph, etc.) |
MemoryDB uses Redis ACLs for access control. Create separate ACL users with restricted command sets and key patterns for each application component - do not share a single superuser across all services.
Pricing Model
| Component | Pricing Basis | Tip |
|---|---|---|
| Node hours | Per hour by node type (db.r6g, db.r7g, etc.) | Reserve production clusters for savings |
| Storage | Per GB-month of data stored (in-memory + transaction log) | Size appropriately; no cold tier unlike Timestream |
| Snapshot storage | Per GB-month beyond free allowance (1x data size free) | Reduce retention for non-production clusters |
MemoryDB is priced roughly 20-30% higher than equivalent ElastiCache Redis nodes to cover the transaction log infrastructure. For workloads where you would otherwise run ElastiCache + a durable database, MemoryDB is often cheaper and simpler in total cost of ownership.
Interview Focus Points
- 1What is the difference between MemoryDB for Redis and ElastiCache Redis?
- 2When would you choose MemoryDB over ElastiCache as a data store?
- 3How does MemoryDB achieve durability while maintaining microsecond read latency?
- 4What is the write latency trade-off in MemoryDB compared to ElastiCache?
- 5Describe a use case where MemoryDB replaces both ElastiCache and RDS in an architecture.
- 6What Redis features are not available in MemoryDB?
- 7How does MemoryDB handle failover? What is the RTO?
- 8How does ACL-based authentication work in MemoryDB?