All interview questions

Redis Interview Questions

Decide what Redis owns and what it only accelerates. That distinction determines whether expiry, failover or an eviction is acceptable.

Try answering aloud before opening each explanation.

Try the Redis practice demo

Foundations

When would you use a sorted set rather than a set?

Use a sorted set when members need a score and range queries by rank or score. A regular set is simpler for unordered membership and set algebra.

How does expiration differ from eviction?

Expiration removes keys after their TTL. Eviction removes eligible keys under memory pressure according to the policy, which means a key can disappear before its TTL.

Does a normal SET preserve an existing TTL?

Replacing a value with SET normally clears its TTL unless you use an option such as KEEPTTL or set a new expiry. Include expiry in the write when it is a business requirement.

How does a hash differ from storing a JSON string under one key?

A hash lets clients read and update named fields independently. A JSON string is an opaque string to ordinary Redis commands and usually requires replacing the serialized value.

What does pipelining improve?

It reduces network round trips by sending many commands without waiting after each one. It does not make the commands an atomic group.

Applied

How does WATCH help with a read-modify-write sequence?

It makes EXEC conditional on the watched keys remaining unchanged. If EXEC aborts, reread and retry within a bound; watching does not prevent other clients from writing.

Why prefer SCAN over KEYS on a busy server?

SCAN iterates in bounded steps rather than scanning the entire keyspace in one blocking operation. It can return duplicates and does not give a stable snapshot during changes.

What does a Streams consumer group track?

It distributes deliveries among consumers and records pending entries until acknowledgement. Inspect and reclaim abandoned entries and make handlers tolerate redelivery.

How do RDB snapshots and AOF differ when recovering after a crash?

RDB captures point-in-time state; later changes can be lost. AOF replays recorded writes, with the possible loss window determined by its sync policy. Test restoration for either mode.

Why can two Redis Cluster keys fail in one multi-key command?

Many multi-key operations require all keys to be in the same hash slot. A shared hash tag can colocate related keys, but too much colocation can create hot slots.

Production scenarios

What causes a hot key when total cache usage appears healthy?

A single popular key can overload the shard or network connection that serves it. Measure skew by key pattern or shard, then consider request coalescing or a bounded local cache where freshness permits.

Can asynchronously replicated Redis lose an acknowledged write after failover?

Yes, the promoted replica may not have received the write. When the loss is unacceptable, treat this as an architecture requirement rather than assuming ordinary acknowledgement provides durable consensus.

Why add randomness to TTLs for a large preloaded cache?

If many keys expire together, the database can see a synchronous miss storm. Spread expirations and coalesce concurrent refreshes of popular individual keys.

What do you measure before increasing Redis maxmemory?

Separate evictions, object size, fragmentation, replica buffers and process RSS. Increasing the configured limit can move the failure to host memory without addressing command latency or key growth.

How should a service behave when its Redis cache is unavailable?

If the authoritative store can serve the request, use bounded fallback and load shedding to protect it. If Redis stores essential coordination state, fail according to that contract rather than assuming it is safe to bypass.

Further reading

Official documentation

Related question sets