Top Redis Interview Questions & Answers

Redis Interview Questions.jpg

1. What are the main use cases of Redis?​

Answer:
Redis is commonly used for:
  • Caching (most common)
  • Session storage
  • Real-time analytics
  • Leaderboards (gaming apps)
  • Pub/Sub messaging systems
💡 Interview Tip:
Say: “Redis is best suited for low-latency, high-throughput use cases where speed is critical.”

2. Why is Redis so fast?​

Answer:
  • In-memory storage (no disk I/O)
  • Single-threaded event loop (no locking overhead)
  • Optimized data structures
💡 Add this line:
"Redis trades durability for speed in many use cases."

3. What data structures does Redis support?​

Answer:
Redis supports:
  • Strings
  • Lists
  • Sets
  • Sorted Sets (ZSET)
  • Hashes
  • Bitmaps
  • HyperLogLog
💡 Interview edge:
Sorted Sets are widely used for leaderboards and ranking systems.

4. What is caching in Redis?​

Answer:
Caching stores frequently accessed data in Redis to reduce database load.
Example:
  • DB query takes 100ms
  • Redis fetch takes 1ms
👉 Pattern:
  • Check Redis → If miss → Fetch from DB → Store in Redis

5. What is cache invalidation?​

Answer:
It ensures stale data is removed or updated.
Common strategies:
  • TTL (Time To Live)
  • Write-through
  • Write-back
  • Cache-aside (most common)
💡 Strong answer:
"Cache invalidation is one of the hardest problems in distributed systems."

6. What is TTL in Redis?​

Answer:
TTL (Time To Live) defines how long a key remains in Redis.
Example:
SET key value EX 60
👉 Key expires after 60 seconds.

7. What is Redis persistence?​

Answer:
Redis supports two persistence mechanisms:
  1. RDB (Snapshotting)
    • Saves data at intervals
    • Faster, but may lose data
  2. AOF (Append Only File)
    • Logs every write operation
    • More durable
💡 Best practice:
  • Use both for production

8. What is the difference between Redis and Memcached?​

FeatureRedisMemcached
Data TypesMultipleString only
PersistenceYesNo
PerformanceHighHigh
Use CaseAdvanced cachingSimple caching

9. What is Redis Pub/Sub?​

Answer:
A messaging system where:
  • Publisher sends messages
  • Subscribers receive them
Use cases:
  • Chat apps
  • Notifications
  • Event-driven systems

10. What is Redis clustering?​

Answer:
Redis Cluster allows:
  • Horizontal scaling
  • Data sharding
  • High availability
👉 Data is distributed across multiple nodes.

11. What is sharding in Redis?​

Answer:
Sharding splits data across multiple Redis instances.
Example:
  • User 1 → Node A
  • User 2 → Node B

12. What is replication in Redis?​

Answer:
  • Master-Slave architecture
  • Slaves replicate data from master
👉 Improves:
  • Read scalability
  • Fault tolerance

13. What is Redis Sentinel?​

Answer:
Sentinel provides:
  • Monitoring
  • Automatic failover
  • High availability

14. What are common Redis eviction policies?​

When memory is full:
  • LRU (Least Recently Used)
  • LFU (Least Frequently Used)
  • Random eviction
  • No eviction

15. How does Redis handle concurrency?​

Answer:
  • Single-threaded model
  • Uses event loop
👉 Avoids race conditions and locks

16. What is pipelining in Redis?​

Answer:
Allows multiple commands to be sent without waiting for responses.
👉 Improves performance significantly

17. What is a distributed lock in Redis?​

Answer:
Used to ensure only one process accesses a resource.
Example:
  • SETNX (set if not exists)
👉 Advanced: Redlock algorithm

18. What are Redis transactions?​

Answer:
Commands:
  • MULTI
  • EXEC
  • DISCARD
👉 Ensures atomic execution

19. What is HyperLogLog?​

Answer:
Used for approximate counting of unique elements
👉 Example:
  • Counting unique website visitors

20. When should you NOT use Redis?​

Answer:
Avoid Redis when:
  • Data must be strictly durable
  • Dataset is larger than memory
  • Complex queries required (use SQL/NoSQL DB)
 
Back
Top