Scrivio Interview library

Redis internals and performance

35 questions in 8 subtopics.

About this topic

Redis looks simple from the outside, but both its speed and its failures come from how it works inside. One main thread executes every command, helped by I/O threads, background threads and forked child processes. Data sits in compact encodings until it grows, and memory use is shaped by the allocator, client buffers and the maxmemory limit. Most production trouble with Redis, from latency spikes and surprise evictions to saturated networks, traces back to these internals, to oversized or overused keys, or to round trips between client and server. The questions cover the event loop, encodings, memory and fragmentation, big and hot keys, latency diagnosis, pipelining, client-side caching with RESP3, and the choice between Redis versions, Valkey and managed services, from first principles to fleet-wide strategy.

Event loop, single thread and I/O threads

Redis runs commands one at a time on a single main thread driven by an event loop, which makes each command atomic and avoids locks but means one slow command delays everyone. Understand what I/O threads, background threads and forked children take off that thread, what housekeeping still runs on it, and how to tell whether an instance is limited by syscalls, by command cost or by a single core.

ConceptFoundations7 min read

Redis executes every client command on one main thread, yet a single instance commonly serves well over 100,000 simple operations per second.

Explain how the Redis event loop serves thousands of connections with one thread, why that is fast, and what the single thread means for the atomicity and the cost of individual commands.
InternalsIntermediate7 min read

Although commands execute on one thread, a Redis process runs several threads and child processes, and some housekeeping still runs on the main thread between client requests.

Which work does Redis do off the main thread or in a child process, which background work still runs on the main thread, and which settings move expensive work away from it?
DebuggingIntermediate6 min read

A Redis 7.2 primary serves 160,000 small GET and SET operations per second from 4,000 client connections on a 16-vCPU host. One core sits at 100 percent and p99 latency has climbed from 0.4 ms to 6 ms at peak.

INFO cpu shows used_cpu_sys growing faster than used_cpu_user, and SLOWLOG is empty. What is the bottleneck, and what would you change, in what order?
ScenarioAdvanced6 min read

A shopping platform's session and cart Redis primary peaks at 85 percent of one core today. A sales event in six weeks is forecast to bring three times the normal peak, and the deployment is a single primary with replicas, not a cluster.

How do you decide what to change before the event, and how do you prove that the system will hold?
LeadershipPrincipal6 min read

Multi-threaded Redis-compatible engines, and the I/O threading work in Valkey 8 and Redis 8, promise far more throughput per node than the classic single main thread, and vendors pitch them as drop-in replacements.

Your company runs about 300 Redis instances, and engineers propose standardising on a multi-threaded compatible engine to cut the node count. How do you decide, and what would you require before any switch?

Internal encodings and memory layout

Each Redis data type has a compact encoding for small values, such as listpack and intset, and a general structure for large ones, such as hashtables and skiplists. Know the thresholds that trigger conversion, why conversion is one-way while a key lives, how much per-key overhead costs, and how encoding choices trade memory for CPU on every lookup.

ConceptFoundations6 min read

Redis stores small values in compact encodings and switches to general-purpose structures when they grow, which is why the same data type can use very different amounts of memory.

What does OBJECT ENCODING report for strings, hashes, sets, sorted sets and lists, when does Redis convert from a compact encoding to a regular one, and why does it matter?
CodingIntermediate6 min read

A link-shortening service maps 200 million numeric short ids to numeric target ids in Redis. Stored as one string key per id, the instance uses about 16 GB, mostly per-key overhead rather than data.

Show how bucketing into small hashes reduces memory, with the key scheme and commands, and explain what you give up.
DebuggingIntermediate6 min read

A user-profile store keeps 30 million hashes of about 12 short fields each in Redis 7.2, using 9 GB. A release adds a free-text bio field, often 100 to 300 characters long, and within a day used_memory reaches 26 GB.

Explain why memory nearly tripled when the data grew only a little, how you would confirm it, and what you would change.
ScenarioAdvanced6 min read

A shared Redis fleet is at 85 percent of maxmemory on most nodes, and the budget for new nodes is frozen for two quarters. A platform engineer proposes raising zset-max-listpack-entries and hash-max-listpack-entries to 1024 everywhere to save memory.

How do you evaluate this proposal and roll it out, if at all?

Memory usage, fragmentation and maxmemory

Redis memory is more than the dataset: allocator fragmentation, client and replication buffers, the replication backlog and copy-on-write during forks all count. Learn to read INFO memory, to tell fragmentation from swapping, to understand what maxmemory limits and what it ignores, and to size hosts and shards so persistence and failover do not push a node over its limit.

ConceptFoundations6 min read

INFO memory is the first place to look when a Redis instance seems to use more RAM than its data should need.

Explain used_memory, used_memory_rss, used_memory_peak, mem_fragmentation_ratio and maxmemory, and what a fragmentation ratio of 1.6 or of 0.7 tells you.
DebuggingIntermediate6 min read

A cache Redis with maxmemory 10 GB and allkeys-lru normally evicts nothing. At 14:05 evicted_keys jumps to 40,000 per second, the hit rate falls from 96 to 60 percent and the key count drops by a third, though no new data was written.

INFO clients shows client_recent_max_output_buffer at 2.1 GB. What happened, and how do you stop it from happening again?
DebuggingIntermediate6 min read

A cache Redis on a 32 GB VM held 22 GB of data. A cleanup job deleted about 40 percent of the keys, yet the host still shows Redis at 23 GB resident. INFO reports used_memory of 13 GB and mem_fragmentation_ratio 1.75.

Why did resident memory not fall, and what are your options to reclaim it without an outage?
DesignAdvanced7 min read

A team needs a Redis deployment holding about 120 GB of data with AOF and daily RDB snapshots, one replica per primary, and a steady 30,000 writes per second.

How do you size memory per node, choose the shard size and set maxmemory, and which operating-system settings matter?
LeadershipPrincipal6 min read

Memory is the main cost of a Redis fleet, and in many companies nobody can say which keys use it or whether they are still needed. Finance asks the platform group to cut Redis spending by 40 percent within a year.

As the senior technical leader, how do you approach this without causing incidents?

Big keys and hot keys

A big key is a value with huge size or element count, and a hot key is one that takes a large share of requests. Both concentrate load on one thread, one shard or one network link. Understand how to find them safely, why they block servers, saturate networks and break resharding, and the patterns for splitting, caching and governing them.

ConceptFoundations6 min read

A big key holds a very large value or very many elements, and a hot key receives a large share of all requests. Both concentrate load on one key and one thread, and both are hard to see from the application.

How do you find big keys and hot keys in a running Redis instance without hurting it, and what does each tool actually measure?
DebuggingIntermediate5 min read

Twelve application pods read a 900 KB JSON configuration blob from Redis on every request, about 3,000 reads per second in total. Other services sharing the instance start timing out, while Redis CPU is only 35 percent.

INFO stats shows instantaneous_output_kbps near 2.6 GB per second. Diagnose the problem and fix it.
ScenarioIntermediate6 min read

A live-streaming service counts total views per stream with INCR on one key. A popular stream reaches 250,000 increments per second, and the Redis Cluster node that owns the key's slot pins at 100 percent CPU while other nodes are idle.

Redesign the counter so the load spreads, and explain what readers of the count now have to do.
LeadershipAdvanced6 min read

In one quarter a shared Redis platform used by 80 services had three incidents: a 6 GB sorted set that blocked a node when deleted, a hot key that saturated one shard during a promotion, and a 2 GB list that broke a resharding.

What standards, tooling and ownership would you put in place so big and hot keys are caught before they cause incidents?

Latency diagnosis with SLOWLOG and LATENCY

Redis latency can come from slow commands, forks, disk syncs, expiry and eviction work, the network, or the client itself. SLOWLOG only shows command execution, while the LATENCY monitor, INFO fields and client-side metrics show the rest. Know what each tool measures, how to match a spike to its cause, and how to turn this into objectives for a shared platform.

ConceptFoundations5 min read

Redis keeps a slow log of commands whose execution took longer than a threshold. It is the first tool people reach for when Redis looks slow, and it is often misread.

What exactly does SLOWLOG record, how is it configured, and what kinds of slowness will it never show?
DebuggingIntermediate6 min read

A Redis primary holding 38 GB on a cloud VM shows a 700 ms latency spike roughly every 20 minutes. Persistence uses RDB snapshots (save 1200 10000) and AOF everysec, and SLOWLOG shows nothing at those times.

How do you use the LATENCY monitor and INFO to prove the cause, and what do you change?
DebuggingIntermediate6 min read

A Spring Boot service using Lettuce reports Redis p99 latency of 45 ms in its metrics. On the server, SLOWLOG is empty, CPU is 30 percent, and redis-cli --latency run on the Redis host shows 0.2 ms.

Where can the missing 45 ms come from, and how do you narrow it down?
LeadershipPrincipal5 min read

A checkout path now makes several Redis calls per request, and product leadership wants a guaranteed p99 under 2 ms for Redis across about 120 instances that one platform team runs for many product teams.

How would you set and run latency objectives for this shared Redis platform, and what would you refuse to promise?

Pipelining and round trips

For small commands, the network round trip usually costs far more than the work Redis does, so the number of round trips sets the speed of a client. Understand pipelining, multi-key commands, transactions and scripts as ways to cut round trips, which of them are atomic, how Spring Data Redis and Lettuce expose them, and how distance between service and Redis changes designs.

ConceptFoundations6 min read

Every Redis command is a request and a reply over the network, so for small commands the round-trip time, not Redis itself, usually limits how fast one client can go.

Compare pipelining, multi-key commands such as MGET, MULTI/EXEC transactions and Lua scripts as ways to cut round trips. Which are atomic, and when would you choose each?
DebuggingFoundations6 min read

A nightly Spring Boot job loads 2 million product summaries into Redis with one SET key value EX 86400 call per item. It takes 40 minutes, Redis CPU stays under 5 percent, and the job runs in another availability zone with a round trip of about 1.1 ms.

Explain why it is slow and how you would make it finish in a minute or two.
CodingIntermediate7 min read

Spring Data Redis and Lettuce offer several ways to send many commands efficiently, and some of them affect other code that shares the same connection.

Show how to read 500 hashes in one round trip with RedisTemplate.executePipelined, and how to batch commands by hand with the Lettuce async API. What mistakes do teams make with each?
ScenarioAdvanced6 min read

To cut costs, a pricing service was moved to a second region while its Redis stayed in the first, about 45 ms away. Each request makes 8 sequential Redis calls, and p99 rose from 12 ms to over 380 ms.

What do you change in the short term and in the design, and how do you decide whether Redis should move?

Client-side caching and RESP3

Server-assisted client-side caching lets clients keep local copies of Redis keys and drop them when the server reports a change. It relies on CLIENT TRACKING in default or broadcasting mode and works best with the RESP3 protocol. Know how invalidations flow, what the server pays to track keys, and the races and failures a correct client must handle.

ConceptFoundations6 min read

Since Redis 6 the server can help clients keep local copies of keys by telling them when those keys change, a feature called client-side caching or key tracking.

Explain how CLIENT TRACKING works in default mode and in broadcasting mode, and what RESP3 changes about how invalidations reach the client.
InternalsIntermediate6 min read

A team builds server-assisted client-side caching into a Java service and wants to know whether it can ever serve a value that Redis has already changed.

Walk through the races and failure cases in client-side caching and how a correct client handles each one.
DebuggingIntermediate6 min read

After 60 pods enabled client-side caching in default tracking mode, Redis memory grew by about 2 GB and CPU by 20 percent. INFO shows tracking_total_keys near 1,000,000, and the pods' local hit rate is far below what the team expected.

What is going on, and how would you reconfigure the caching?
DesignAdvanced6 min read

Forty services read feature flags and pricing rules from Redis at a combined 400,000 reads per second. The data is about 50 MB, changes a few times a minute, and changes must be visible within one second.

Design the caching approach, comparing server-assisted client-side caching with local caches invalidated through pub/sub, and say what consistency you can promise.

Redis versions, Valkey and managed services

Redis 7 and 8, the Valkey fork and many managed services now coexist, with shared roots but different licences, features and restrictions. Know what each major version added, how compatible Valkey and Redis are, what managed services commonly restrict, and how to upgrade or migrate under live traffic while keeping a way back.

ConceptFoundations6 min read

Since 2024 the Redis ecosystem has split: Redis changed its licences, the Valkey fork appeared, and cloud providers offer managed services built on one or the other.

Explain what Valkey is, how compatible it is with Redis, and the main features of Redis 7.x, Redis 8 and Valkey 8 that a Java developer would notice.
DebuggingFoundations6 min read

A Spring Boot application moved from a self-managed Redis to a managed Redis-compatible service. It now fails at startup with 'ERR unknown command CONFIG' coming from Spring Session, and an internal admin page that lists keys times out.

Explain both failures and how to fix them.
ScenarioIntermediate6 min read

A team runs a self-managed Redis 6.2 primary with two replicas and Sentinel, holding 25 GB with AOF on. It plans an in-place upgrade to 7.2 on a weekday evening with traffic still flowing.

Plan the upgrade: which changes between 6.2 and 7.2 matter, in which order do you upgrade the nodes, and how do you keep a way back?
ScenarioAdvanced6 min read

A company runs 30 self-managed Redis 6 deployments, some clustered, for caches, sessions and rate limits. It has decided to move them to a managed Valkey service in the same cloud with no downtime that users notice.

Design the migration per workload type, including how you move data under live traffic, validate it and roll back.
LeadershipPrincipal5 min read

Redis 8 ships search, JSON, time series and vector features in its main distribution, Valkey offers some of them as modules, and managed services support different subsets. Teams have started using whatever their current engine offers.

How do you set a long-term policy on which engine features teams may depend on, so the company keeps its options open?