Redis Interview Questions and Answers
Data structures, persistence, expiry, pub/sub and caching patterns.
Whether you are preparing for entry-level Redis interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.
1 How do you implement a distributed lock with Redis? Hard
A common implementation is SET key value NX PX ttl. NX sets the key only if it does not exist, and PX gives the lock an expiry so a crashed holder cannot deadlock the system. The value should be a unique token so only the owner releases the lock.
token = str(uuid.uuid4())
if redis.set("lock:order:42", token, nx=True, px=10000):
try:
process_order(42)
finally:
redis.eval(
"if redis.call('get', KEYS[1]) == ARGV[1] then "
"return redis.call('del', KEYS[1]) else return 0 end",
1, "lock:order:42", token)
The Lua script makes check-and-delete atomic, preventing one client from deleting another's lock. For failover safety use Redlock across independent nodes, but note it is contested and cannot give strict fencing guarantees. Long tasks should renew the TTL and pass fencing tokens downstream.
2 How does Redis Cluster provide horizontal scaling? Hard
Redis Cluster shards data across nodes using 16384 hash slots. Each key maps to a slot via CRC16(key) mod 16384, and slots are assigned to masters. Clients may query any node; if the slot lives elsewhere the node replies with a MOVED redirection, and smart clients cache the slot map.
Each master has one or more replicas for failover. When a master fails, its replicas promote automatically once a majority of masters agree. Multi-key operations require all keys in the same slot, which hash tags can force: {user:42}:profile and {user:42}:sessions share a slot.
Limitations: only database 0 is available, some cross-key commands are unsupported, and the cluster needs at least three masters for a healthy quorum. Resharding moves slots between nodes online, enabling scaling without downtime.
Frequently Asked Questions About Redis Interviews
What do hiring managers evaluate in Redis technical rounds?
Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.
What are the best interview tips for practicing Redis questions?
Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.