System Design Sim

Learn

How much memory does Redis need? Sizing an ElastiCache node

A cache that's too small quietly stops working: it evicts the keys you need and your database takes the load again. Sizing one is mostly arithmetic: how many keys, how big each one is, how much overhead Redis adds, and how much memory AWS keeps back.

· 3 min read

How big should your cache be?

  1. 10M × (20 + 200 bytes) = 2.20 GB of data
  2. + about 85 bytes of Redis overhead per key = 3.05 GB in memory
  3. ElastiCache keeps 25% of each node in reserve, so you can use 75% of its RAM

The smallest node that holds it is cache.r7g.large (9.8 GiB usable) for about $128/month.

ElastiCache node sizes and nodes needed
NodeRAMUsableNodesPer month
cache.t4g.micro0.5 GiB0.4 GiB8$75
cache.t4g.small1.37 GiB1.0 GiB3$56
cache.t4g.medium3.09 GiB2.3 GiB2$76
cache.r7g.large13.07 GiB9.8 GiB1$128
cache.r7g.xlarge26.32 GiB19.7 GiB1$255
cache.r7g.2xlarge52.82 GiB39.6 GiB1$510

Approximate AWS on-demand prices for us-east-1, read once in October 2026, before free tiers. They may be out of date; check the AWS pricing pages before you budget.

Step 1: count keys and their size

Start with what you'll store: how many keys, how long the keys are, and how big each value is. For a URL shortener, a key might be a 7-character short code and the value a 100-byte URL. For sessions, a 36-byte ID and a few hundred bytes of JSON.

Raw data = keys × (key size + value size).

Step 2: add Redis's per-key overhead

Redis stores more than your bytes: every key carries pointers, metadata and hash-table space. TheRedis FAQ gives a concrete figure:"1 Million small Keys -> String Value pairs use ~ 85MB of memory" on a 64-bit instance, and an empty instance uses about 3 MB. For small keys that's roughly 85 bytes each, so a good estimate is:

Memory ≈ keys × (key + value + 85 bytes).

When values are small, overhead dominates. Grouping many small fields into one hash uses much less memory than one key per field, as Redis's own memory optimization guideshows.

Step 3: leave room for ElastiCache's reserve

ElastiCache doesn't let your data fill the node. By default it keeps25% of memory in reservefor replication buffers, fragmentation and background saves, and AWS advises 30% on small nodes and 50% on micro nodes. So a 13 GiB node holds about 10 GiB of data. Plan with the usable figure, not the advertised one.

Step 4: size for the hot data, not all of it

A cache doesn't need everything, only what's read often. Traffic is usually skewed: a small share of keys gets most of the reads. Size for that, and let Redis evict the rest. Theeviction docs call allkeys-lru"a good default option" when some keys are read far more than others, and it's more memory-efficient than relying on expiry.

A common starting point is the hottest 20% of a day's reads. Then watch the hit ratio: if it falls as your data grows, the cache is too small.

Worked example: 100 million short links

All linksHottest 20%
Keys100M20M
Raw data (7 + 100 bytes each)10.7 GB2.14 GB
With ~85 bytes overhead per key19.2 GB3.84 GB
Smallest single nodecache.r7g.xlarge, $255/monthcache.r7g.large, $128/month

Caching only the hot fifth cuts the node you need, and the bill, sharply. The cold links fall through to the database.

ElastiCache node sizes

NodevCPUMemoryUsable (75%)Per month
cache.t4g.micro20.5 GiB0.4 GiB$9
cache.t4g.small21.37 GiB1.0 GiB$19
cache.t4g.medium23.09 GiB2.3 GiB$38
cache.r7g.large213.07 GiB9.8 GiB$128
cache.r7g.xlarge426.32 GiB19.7 GiB$255
cache.r7g.2xlarge852.82 GiB39.6 GiB$510

Prices are for ElastiCache for Valkey, which AWS prices 20% below Redis OSS on node-based clusters.

When one node isn't enough

  • Too much data: cluster mode splits keys across several primaries, each holding part of the data.
  • Availability: add a replica per shard, so a node failure fails over instead of emptying the cache.
  • Throughput: rarely the limit. A single node handles tens to hundreds of thousands of simple operations per second; a published benchmark measured about 205,000 on an r7g.2xlarge without I/O threads. Memory runs out first.

See what happens when a cache restarts empty in The Stampede challenge, or put one in front of a struggling database in Cache Money.

Frequently asked questions

How much memory does Redis use per key?

More than the key and value alone. The Redis FAQ says 1 million small key-value pairs use about 85 MB on a 64-bit instance, which works out to roughly 85 bytes each for very small keys. For estimates, add about 85 bytes of overhead to the size of each key and value.

What is reserved memory in ElastiCache?

ElastiCache reserves part of each node's memory for replication buffers, fragmentation and background saves. The default reserved-memory-percent is 25%, so a 13 GiB node stores about 10 GiB of data. AWS suggests 30% on small nodes and 50% on micro nodes.

What happens when Redis runs out of memory?

It depends on the eviction policy. With allkeys-lru, Redis evicts the least recently used keys to make room, which suits a cache. With no eviction policy, it starts rejecting writes.

Do I need to cache all my data?

No. Traffic is usually skewed: a small share of keys gets most of the reads. A common starting point is to size the cache for the hottest 20% of a day's reads, then watch the hit ratio and grow if it drops.

One system design problem a week

A real scenario, its constraints, and where the obvious design breaks.

One email a week. Unsubscribe any time. Privacy

Now break one yourself.

The first challenge takes about two minutes. No signup.