Prev Next

Database / ValKey Interview questions

Explain the internal working of Valkey's LRU and LFU eviction algorithms?

Tracking exact least-recently-used order for every key would be too expensive at scale, so Valkey approximates it: each key carries a compact last-access timestamp field, and on eviction the server samples a small random set of keys, controlled by maxmemory-samples (default 5), and evicts whichever one in that sample was accessed longest ago, repeating as needed.

LFU mode instead tracks a probabilistic, logarithmic access-frequency counter per key that increments with decreasing probability as it grows and decays gradually over time, so an old burst of activity doesn't keep a key "hot" forever; eviction then targets the lowest-frequency key among a sampled set.

LFU tends to suit workloads with a genuinely persistent hot subset of keys better than LRU, which is more sensitive to short-term recency.

Approximated LRU eviction works by...
LFU's access-frequency counter is designed to...

More Related questions...

What is Valkey? What is the purpose of Valkey? What are the data types supported by Valkey? How do you install Valkey on a Linux server? Define Valkey persistence? What is RDB persistence in Valkey? What is AOF persistence in Valkey? Describe Valkey replication? List the eviction policies supported by Valkey? What is the purpose of Valkey Sentinel? What is Valkey Cluster? How do you apply a TTL to a key in Valkey? What is the purpose of the valkey.conf configuration file? How do you use the Valkey CLI to connect to a remote, password-protected server? Explain the basic architecture of a Valkey server? Why was Valkey created? Why do we use Valkey instead of Redis? What is the difference between Valkey and Redis? How does Valkey Cluster achieve horizontal scaling through hash slots? How does Valkey handle automatic failover in Sentinel mode? When should you choose Valkey Cluster over Sentinel? What is the difference between RDB and AOF persistence? How can you optimize memory usage in Valkey? How do you troubleshoot high latency in a Valkey deployment? Explain the lifecycle of a command from a Valkey client to execution and response? Explain the execution flow of primary-replica replication in Valkey? Explain the internal working of the Valkey single-threaded event loop? Why doesn't Valkey execute commands using multiple threads by default? What happens when a primary node fails in a Valkey Cluster? Which is better and why: Valkey Cluster or client-side sharding? How does Valkey implement publish/subscribe messaging? What is the difference between LPUSH and RPUSH? How do you use Valkey Streams for event processing? What are Valkey modules and how do you load one? How does Valkey handle expired key deletion internally? What is the difference between Valkey and Memcached? How do you secure a Valkey deployment in production? What is the role of ACLs in Valkey? How does Valkey handle memory fragmentation? What is the difference between WAIT and replica acknowledgment in Valkey? How do you perform a zero-downtime Valkey version upgrade? Explain the internal working of Valkey's hash slot mechanism in cluster mode? How do you troubleshoot a split-brain scenario with Valkey Sentinel? Explain the difference between Valkey Cluster mode and standalone mode? How does Valkey achieve high availability? What is the difference between synchronous and asynchronous replication in Valkey? How do you monitor Valkey performance in production? Explain the internal working of Valkey's LRU and LFU eviction algorithms? Why should you avoid running the KEYS command in production? How does Valkey's multi-threaded I/O model improve throughput over classic single-threading?
Show more question and Answers...


Comments & Discussions