Database / ValKey Interview questions
How does Valkey handle memory fragmentation?
Valkey defaults to the jemalloc memory allocator, which generally handles the frequent small allocations and deallocations typical of a key-value workload better than a generic allocator, reducing how much fragmentation builds up over time.
INFO memory exposes a mem_fragmentation_ratio so you can see how much physical memory is being used versus what the dataset actually needs, and enabling activedefrag lets Valkey incrementally compact fragmented memory in the background during spare CPU cycles, without blocking client traffic.
Fragmentation tends to climb after large deletes, resizes, or workloads that mix very differently sized objects, so avoiding extreme size variance and tuning eviction alongside active defrag both help keep it in check.
More Related questions...