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
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
"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
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
- 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)
"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
7. What is Redis persistence?
Answer:Redis supports two persistence mechanisms:
- RDB (Snapshotting)
- Saves data at intervals
- Faster, but may lose data
- AOF (Append Only File)
- Logs every write operation
- More durable
- Use both for production
8. What is the difference between Redis and Memcached?
| Feature | Redis | Memcached |
|---|---|---|
| Data Types | Multiple | String only |
| Persistence | Yes | No |
| Performance | High | High |
| Use Case | Advanced caching | Simple caching |
9. What is Redis Pub/Sub?
Answer:A messaging system where:
- Publisher sends messages
- Subscribers receive them
- Chat apps
- Notifications
- Event-driven systems
10. What is Redis clustering?
Answer:Redis Cluster allows:
- Horizontal scaling
- Data sharding
- High availability
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
- 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
16. What is pipelining in Redis?
Answer:Allows multiple commands to be sent without waiting for responses.
17. What is a distributed lock in Redis?
Answer:Used to ensure only one process accesses a resource.
Example:
- SETNX (set if not exists)
18. What are Redis transactions?
Answer:Commands:
- MULTI
- EXEC
- DISCARD
19. What is HyperLogLog?
Answer:Used for approximate counting of unique elements
- 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)