Prev Next

Database / ValKey Interview questions

1. What is Valkey? 2. What is the purpose of Valkey? 3. What are the data types supported by Valkey? 4. How do you install Valkey on a Linux server? 5. Define Valkey persistence? 6. What is RDB persistence in Valkey? 7. What is AOF persistence in Valkey? 8. Describe Valkey replication? 9. List the eviction policies supported by Valkey? 10. What is the purpose of Valkey Sentinel? 11. What is Valkey Cluster? 12. How do you apply a TTL to a key in Valkey? 13. What is the purpose of the valkey.conf configuration file? 14. How do you use the Valkey CLI to connect to a remote, password-protected server? 15. Explain the basic architecture of a Valkey server? 16. Why was Valkey created? 17. Why do we use Valkey instead of Redis? 18. What is the difference between Valkey and Redis? 19. How does Valkey Cluster achieve horizontal scaling through hash slots? 20. How does Valkey handle automatic failover in Sentinel mode? 21. When should you choose Valkey Cluster over Sentinel? 22. What is the difference between RDB and AOF persistence? 23. How can you optimize memory usage in Valkey? 24. How do you troubleshoot high latency in a Valkey deployment? 25. Explain the lifecycle of a command from a Valkey client to execution and response? 26. Explain the execution flow of primary-replica replication in Valkey? 27. Explain the internal working of the Valkey single-threaded event loop? 28. Why doesn't Valkey execute commands using multiple threads by default? 29. What happens when a primary node fails in a Valkey Cluster? 30. Which is better and why: Valkey Cluster or client-side sharding? 31. How does Valkey implement publish/subscribe messaging? 32. What is the difference between LPUSH and RPUSH? 33. How do you use Valkey Streams for event processing? 34. What are Valkey modules and how do you load one? 35. How does Valkey handle expired key deletion internally? 36. What is the difference between Valkey and Memcached? 37. How do you secure a Valkey deployment in production? 38. What is the role of ACLs in Valkey? 39. How does Valkey handle memory fragmentation? 40. What is the difference between WAIT and replica acknowledgment in Valkey? 41. How do you perform a zero-downtime Valkey version upgrade? 42. Explain the internal working of Valkey's hash slot mechanism in cluster mode? 43. How do you troubleshoot a split-brain scenario with Valkey Sentinel? 44. Explain the difference between Valkey Cluster mode and standalone mode? 45. How does Valkey achieve high availability? 46. What is the difference between synchronous and asynchronous replication in Valkey? 47. How do you monitor Valkey performance in production? 48. Explain the internal working of Valkey's LRU and LFU eviction algorithms? 49. Why should you avoid running the KEYS command in production? 50. How does Valkey's multi-threaded I/O model improve throughput over classic single-threading?

1. What is Valkey?

Valkey is an open source, in-memory key-value data store that supports strings, hashes, lists, sets, sorted sets, streams, and other structures, and can be used as a cache, message broker, or primary database. It began life in March 2024 as a fork of Redis 7.2, created after Redis Inc. moved futu...

Read full answer

2. What is the purpose of Valkey?

Valkey exists to give applications extremely fast, sub-millisecond access to data that would otherwise be slow to fetch from a disk-based database on every request. Common purposes include caching to reduce load on a primary database, storing user sessions, powering real-time leaderboards with so...

Read full answer

3. What are the data types supported by Valkey?

Valkey stores every value under a key, but the value itself can take several distinct data types beyond a plain string. String - text, numbers, or binary-safe blobs. List - an ordered, linked sequence of values. Hash - a field-value map, good for representing objects. Set - an unordered collectio...

Read full answer

4. How do you install Valkey on a Linux server?

The three common paths are installing a prebuilt package, building from source, or running the official container image. # Debian/Ubuntu package install sudo apt-get update sudo apt-get install valkey # Build from source git clone https://github.com/valkey-io/valkey.git cd valkey make sudo make i...

Read full answer

5. Define Valkey persistence?

Persistence is the mechanism that writes an in-memory Valkey dataset to disk so it can be reloaded after a restart, crash, or planned maintenance, instead of being lost when the process stops. Valkey supports two persistence mechanisms that can be used independently or together: RDB point-in-time...

Read full answer

6. What is RDB persistence in Valkey?

RDB persistence writes a compact, point-in-time binary snapshot of the entire dataset to a single .rdb file, either on a configured schedule ( save points) or on demand via SAVE or BGSAVE . BGSAVE forks a child process that writes the snapshot using copy-on-write memory pages, so the parent proce...

Read full answer

7. What is AOF persistence in Valkey?

AOF (Append Only File) persistence logs every write command, in order, to a file as it happens, and rebuilds the dataset by replaying that log on startup. How aggressively the log is flushed to disk is controlled by appendfsync : always fsyncs after every write for maximum durability, everysec fs...

Read full answer

8. Describe Valkey replication?

Valkey uses a primary-replica (leader-follower) model where one or more replicas maintain a live copy of a primary's dataset, asynchronously, by default. A replica connects, performs a synchronization using PSYNC , receives either a full RDB transfer or a diskless socket-based transfer, and then ...

Read full answer

9. List the eviction policies supported by Valkey?

When memory usage hits the configured maxmemory limit, the maxmemory-policy directive decides what Valkey does next. noeviction - reject further writes with an error, evict nothing. allkeys-lru - evict the least recently used key across the whole keyspace. volatile-lru - evict the least recently ...

Read full answer

10. What is the purpose of Valkey Sentinel?

Sentinel is a set of separate processes that monitor a primary-replica deployment, detect when the primary becomes unreachable, and automatically promote a replica to take over, without requiring the dataset to be sharded across nodes. Multiple Sentinels run independently and gossip with each oth...

Read full answer

11. What is Valkey Cluster?

Valkey Cluster is a deployment mode that partitions the entire keyspace into 16384 fixed hash slots and distributes those slots across multiple primary nodes, letting a dataset scale horizontally beyond what a single node can hold or serve. Each primary can have one or more replicas, so the clust...

Read full answer

12. How do you apply a TTL to a key in Valkey?

A time-to-live can be attached when a key is created or added afterward, and Valkey will automatically remove the key once it expires. SET session:1001 "user-data" EXPIRE session:1001 3600 # expire in 3600 seconds SET session:1002 "user-data" EX 3600 # set + TTL in one command TTL session:1001 # ...

Read full answer

13. What is the purpose of the valkey.conf configuration file?

valkey.conf is the central configuration file that controls how a Valkey server behaves on startup, covering networking ( bind , port , protected-mode ), persistence ( save points, appendonly ), memory limits and eviction ( maxmemory , maxmemory-policy ), security ( requirepass , ACL file locatio...

Read full answer

14. How do you use the Valkey CLI to connect to a remote, password-protected server?

valkey-cli accepts host, port, and credential flags so it can reach a remote instance without editing any config file. valkey-cli -h 10.0.0.5 -p 6379 -a mypassword # with an ACL user instead of the default user valkey-cli -h 10.0.0.5 -p 6379 --user appuser --pass secret --no-auth-warning # cluste...

Read full answer

15. Explain the basic architecture of a Valkey server?

At its core, a Valkey server keeps the entire dataset in memory as a set of native data structures and serves clients over TCP using the RESP protocol. An event loop built on OS primitives like epoll or kqueue multiplexes many client connections on a single main thread, while newer versions add a...

Read full answer

16. Why was Valkey created?

In March 2024, Redis Inc. announced that future Redis releases would move from the permissive BSD license to a dual Redis Source Available License (RSALv2) / SSPL model, neither of which is an OSI-approved open source license and both of which restrict how cloud providers and some companies can o...

Read full answer

17. Why do we use Valkey instead of Redis?

The most concrete reason is license certainty: Valkey stays under the permissive BSD-3-Clause license, so teams and cloud providers can redistribute or offer it as a managed service without the restrictions attached to Redis's current dual RSALv2/SSPL licensing. Beyond licensing, Valkey has a bro...

Read full answer

18. What is the difference between Valkey and Redis?

Both trace back to the same Redis 7.2 codebase, but they have diverged in licensing, governance, and roadmap since the March 2024 fork. Valkey Redis (current versions) Licensed under permissive BSD-3-Clause Licensed under dual RSALv2 / SSPL Governed by a vendor-neutral community under the Linux F...

Read full answer

19. How does Valkey Cluster achieve horizontal scaling through hash slots?

Every key is mapped to one of 16384 fixed slots using CRC16(key) mod 16384 , or the portion of the key inside curly braces when a hash tag like {user1000}.profile is used to force related keys into the same slot. Each slot is owned by exactly one primary node at a time, and the cluster distribute...

Read full answer

20. How does Valkey handle automatic failover in Sentinel mode?

Sentinels continuously ping the primary and its replicas. When a Sentinel stops getting timely responses from the primary, it privately marks it subjectively down (SDOWN); once enough Sentinels report the same thing, it becomes objectively down (ODOWN) based on the configured quorum. The Sentinel...

Read full answer

21. When should you choose Valkey Cluster over Sentinel?

Cluster mode becomes necessary once the working set or the required write throughput outgrows what a single primary node can hold or handle, since it is the mechanism that actually shards data across many machines. Sentinel is often the better fit when the dataset comfortably fits on one primary ...

Read full answer

22. What is the difference between RDB and AOF persistence?

RDB and AOF trade off recovery speed, file size, and durability guarantees differently, and Valkey lets you enable either, both, or neither. RDB Snapshots AOF Log Compact binary point-in-time snapshot Continuously growing log of write commands Fast restarts from a small file Slower restarts; repl...

Read full answer

23. How can you optimize memory usage in Valkey?

Choosing the right data structure matters most: grouping many related small string keys into a single hash instead can cut per-key overhead significantly, since each standalone key carries its own bookkeeping cost. Setting maxmemory with a sensible eviction policy, attaching TTLs so stale data do...

Read full answer

24. How do you troubleshoot high latency in a Valkey deployment?

Start with LATENCY DOCTOR and LATENCY HISTORY for a summary of recent latency spikes, then check SLOWLOG GET to see which specific commands exceeded the configured slow-log threshold. Look for expensive patterns such as KEYS on a large keyspace, unbounded SORT calls on huge collections, or a sing...

Read full answer

25. Explain the lifecycle of a command from a Valkey client to execution and response?

A client encodes its request using the RESP protocol and sends it over a TCP connection; an I/O thread (or the main thread, in older configurations) reads the bytes off the socket and parses them into a command. flowchart TD A[Client sends RESP command] --> B[I/O Thread: read + parse] B --> C[Mai...

Read full answer

26. Explain the execution flow of primary-replica replication in Valkey?

A replica initiates synchronization by sending PSYNC along with the replication ID and offset it last saw; the primary decides whether a partial or a full resynchronization is possible based on whether that offset is still covered by its backlog. sequenceDiagram participant R as Replica participa...

Read full answer

27. Explain the internal working of the Valkey single-threaded event loop?

The core event loop, built on OS facilities like epoll or kqueue, multiplexes many client sockets on a single thread instead of spawning one thread per connection. Each command that reaches the front of the loop is executed to completion against the in-memory dataset before the next one starts, w...

Read full answer

28. Why doesn't Valkey execute commands using multiple threads by default?

Most Valkey commands are O(1) or O(log N) against in-memory structures, so raw CPU time spent executing them is rarely the actual bottleneck compared to network I/O and protocol parsing at high connection counts. Executing commands on a single thread avoids the lock contention and subtle concurre...

Read full answer

29. What happens when a primary node fails in a Valkey Cluster?

Other nodes gossip continuously over the cluster bus, and when enough of them stop getting timely responses from a given node, they first mark it PFAIL and then, once a quorum of primaries agrees, escalate it to FAIL. Any replica of that failed primary starts a failover election, requesting votes...

Read full answer

30. Which is better and why: Valkey Cluster or client-side sharding?

For most teams, built-in Valkey Cluster is the better default because resharding, slot migration, and failover are handled by the server itself, so application code doesn't need to know which physical node owns a given key. Client-side sharding, where an application or library hashes keys across ...

Read full answer

31. How does Valkey implement publish/subscribe messaging?

SUBSCRIBE and PSUBSCRIBE register a client's interest in specific channels or glob patterns, and PUBLISH broadcasts a message to every client currently subscribed at that moment. Classic pub/sub is fire-and-forget: messages are never stored, so a client that wasn't subscribed when a message was p...

Read full answer

32. What is the difference between LPUSH and RPUSH?

Both commands add one or more elements to a Valkey List, but at opposite ends of it. RPUSH mylist "a" "b" "c" # list is now: [a, b, c] LPUSH mylist "x" # list is now: [x, a, b, c] RPUSH appends at the tail (right), while LPUSH inserts at the head (left). Which one you use, paired with LPOP or RPO...

Read full answer

33. How do you use Valkey Streams for event processing?

Streams model an append-only log of time-ordered entries, each with an auto-generated or explicit ID, which makes them a natural fit for event pipelines. XADD orders * order_id 1042 status "created" XGROUP CREATE orders workers $ XREADGROUP GROUP workers consumer1 COUNT 5 STREAMS orders > XACK or...

Read full answer

34. What are Valkey modules and how do you load one?

Modules are shared libraries that extend the server with new commands, data types, or behavior, running in the same process as Valkey itself rather than as a separate service. # In valkey.conf loadmodule /path/to/module.so # Or at runtime MODULE LOAD /path/to/module.so MODULE LIST Because a modul...

Read full answer

35. How does Valkey handle expired key deletion internally?

Expiration is enforced two ways at once. Passive (lazy) expiration checks a key's TTL whenever it's accessed and deletes it on the spot if the time has passed, before returning any result to the caller. Active expiration runs independently from a periodic background cycle: it samples a subset of ...

Read full answer

36. What is the difference between Valkey and Memcached?

Both are fast in-memory stores, but they differ sharply in data modeling and operational features. Valkey Memcached Rich data types: strings, lists, hashes, sets, sorted sets, streams Simple string/blob values only Optional RDB and/or AOF persistence No persistence; pure cache, lost on restart Bu...

Read full answer

37. How do you secure a Valkey deployment in production?

Start by binding the server to private network interfaces, keeping protected-mode enabled, and placing it behind a firewall or security group so port 6379 isn't reachable from the public internet. Replace a single shared password with ACL users scoped to the least privilege each application actua...

Read full answer

38. What is the role of ACLs in Valkey?

ACLs let an administrator define multiple named users, each with their own password(s), rather than relying on a single shared requirepass value for everyone. ACL SETUSER appuser on >secretpass ~app:* +get +set +del -flushall ACL WHOAMI ACL LIST ACL LOG Each user can be restricted to specific com...

Read full answer

39. 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...

Read full answer

40. What is the difference between WAIT and replica acknowledgment in Valkey?

Replica acknowledgment, sent as REPLCONF ACK , is the continuous, low-level heartbeat a replica sends the primary reporting the replication offset it has applied so far; it's used internally for tracking lag and enabling partial resynchronization. WAIT numreplicas timeout is a client-facing comma...

Read full answer

41. How do you perform a zero-downtime Valkey version upgrade?

In a replicated or clustered deployment, upgrade replicas first, one at a time: stop the replica, swap the binary, restart it, and wait for it to fully catch up before moving to the next one. Once an upgraded replica is caught up, fail over to it so it becomes the new primary, then upgrade the ol...

Read full answer

42. Explain the internal working of Valkey's hash slot mechanism in cluster mode?

Each of the 16384 slots is owned by exactly one primary at a time, and the current ownership map, along with a configuration epoch used to resolve conflicting claims, is gossiped continuously between nodes over the cluster bus. flowchart LR subgraph Migration S1[Slot on Source Node] -->|marked MI...

Read full answer

43. How do you troubleshoot a split-brain scenario with Valkey Sentinel?

Split-brain risk comes from network partitions where an isolated old primary keeps accepting writes while Sentinels on the majority side of the partition promote a replica to a new primary. Setting min-replicas-to-write and min-replicas-max-lag mitigates this by making the isolated primary refuse...

Read full answer

44. Explain the difference between Valkey Cluster mode and standalone mode?

The two modes differ in how the dataset is distributed and how high availability is achieved. Cluster Mode Standalone Mode Data automatically sharded across 16384 slots and many nodes Entire dataset lives on a single primary Multi-key operations limited to keys in the same slot (hash tags) Multi-...

Read full answer

45. How does Valkey achieve high availability?

High availability comes from layering several mechanisms rather than any single feature: replication keeps hot standby copies of the data on other nodes, and automated failover, Sentinel outside Cluster mode or built-in cluster failover inside it, promotes a replica the moment a primary becomes u...

Read full answer

46. What is the difference between synchronous and asynchronous replication in Valkey?

Valkey defaults to asynchronous replication, and offers the WAIT command as an opt-in way to approximate stronger durability on specific writes. Default (Async) WAIT-backed Client gets a reply immediately; replicas catch up in the background Client blocks until N replicas acknowledge the write Sm...

Read full answer

47. How do you monitor Valkey performance in production?

INFO is the quickest built-in check, surfacing memory usage, replication state, connected-client counts, and command statistics in one call, while LATENCY HISTORY / LATENCY DOCTOR and SLOWLOG GET zero in on specific latency problems and slow commands. For continuous observability, exporters that ...

Read full answer

48. 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 whichev...

Read full answer

49. Why should you avoid running the KEYS command in production?

KEYS scans the entire keyspace in a single pass on Valkey's main thread, so on a large dataset it can block every other client for a noticeable stretch of time, producing latency spikes or timeouts across the whole deployment. # Avoid in production: KEYS user:* # Prefer: SCAN 0 MATCH user:* COUNT...

Read full answer

50. How does Valkey's multi-threaded I/O model improve throughput over classic single-threading?

In the classic single-threaded design, one thread handles socket reads, protocol parsing, command execution, and socket writes for every client, which works well for cheap commands but lets I/O and parsing overhead become the bottleneck once connection counts get high. Starting with Valkey 8.0 an...

Read full answer

«
»

Comments & Discussions