Skip to content
/
Suscribirse Subscribe

Detrás del telón hay sistemas, no magia. Arquitectura de software, IA y computación de bajo nivel para las trincheras de producción.

Behind the curtain there are systems, not magic. Software architecture, AI, and systems engineering from the production trenches.

PRODUCTION REDIS / VALKEY SIZING · JEMALLOC OVERHEAD + HIT RATIO

Estimate true Redis or Valkey RAM footprint including 64-bit metadata pointers (dictEntry + redisObject + SDS), jemalloc bucket rounding, fork() Copy-on-Write safety margin for snapshots/AOF, and origin database offload from your Cache Hit Ratio.

Raw key + value payload
—
Actual RAM (with overhead)
—
Safe host RAM target
—
Origin DB miss traffic
—

Real 64-Bit Redis & Valkey Memory Sizing Formula

The classic cache-sizing blunder is multiplying key count by JSON byte length while ignoring 64-bit hash-table metadata and jemalloc allocation buckets. Per the official Redis Memory Optimization Guide, consolidating small entries into listpack-encoded Hashes cuts per-entry pointer overhead substantially.

Bytes_per_Key ≈ jemalloc_align(dictEntry_24B + redisObj_16B + SDS(key) + SDS(val))
Dataset_RAM = Keys × Bytes_per_Key × Fragmentation_Factor(1.12)
Safe_Host_RAM = Dataset_RAM × Fork_CoW_Multiplier (1.5× – 2.0× for RDB/AOF/replicas)
Origin_RPS = Total_RPS × (1 - Cache_Hit_Ratio)

Production Sizing Benchmarks (5 Million Entries)

Workload Raw Payload (5M keys) Actual Process RAM Safe Host RAM (with RDB/AOF)
Tiny feature flags (16 B + 16 B) 0.15 GiB ~0.61 GiB (4× pointer tax) 1.5 – 2 GiB RAM
User sessions / JSON (32 B + 256 B) 1.34 GiB ~1.95 GiB 3 – 4 GiB RAM
Same entries packed in compact Hash 1.34 GiB ~1.55 GiB (-20% RAM) 2.5 – 3 GiB RAM
Heavy catalog objects (40 B + 2 KB) 9.7 GiB ~11.4 GiB 18 – 24 GiB RAM (CoW headroom)

Frequently Asked Questions

Why provision 1.5× to 2× RAM over the active dataset size?

During BGSAVE snapshots or full replica resyncs, Redis/Valkey spawns a child process via fork(). Under heavy write churn, OS Copy-on-Write (CoW) duplicates modified memory pages, triggering Linux OOM-killer crashes when memory headroom is tight.

When should I pack small keys into a Hash?

Whenever storing millions of entries under ~100 bytes. Packing 100–500 fields per Hash triggers linear listpack encoding, cutting metadata pointer waste several-fold. You can also size the origin database behind your cache with our PostgreSQL RAM & Connections Sizer and track availability budgets via our SLA Uptime & Error Budget Calculator.

Suscribirse Subscribe