You need to design a distributed caching layer using Redis for a web application that handles millions of users. Which architecture component is essential to ensure data consistency and high availability?
Think about how Redis handles failover and keeps the cache available during node failures.
Redis Sentinel provides monitoring, notification, and automatic failover to keep the cache highly available and consistent. Single instances or local memory do not provide failover, and Memcached lacks built-in replication.
Your application uses Memcached to cache user session data. The dataset is growing beyond the capacity of a single Memcached server. What is the best approach to scale Memcached horizontally?
Consider how Memcached clients decide which server to use for a given key.
Consistent hashing allows clients to distribute keys evenly across multiple Memcached servers, enabling horizontal scaling. Increasing RAM on one server has limits, and Memcached supports horizontal scaling via client-side hashing.
Your team must choose between Redis and Memcached for caching user sessions. Which tradeoff is most important when deciding?
Think about features and use cases of Redis and Memcached.
Redis supports persistence and complex data types like lists and sets, making it versatile. Memcached is simpler and optimized for fast key-value caching but lacks persistence and complex data structures.
Which cache invalidation strategy is best suited for a distributed cache to maintain data freshness without overwhelming the backend database?
Consider balancing freshness and load on the database.
TTL expiration ensures cache entries expire after a set time, and lazy loading reloads data on cache miss. Immediate deletion can cause high load, and never expiring risks stale data. Writing only to cache breaks data consistency.
Your system expects 10 million active users, each with an average session size of 2 KB. You want to cache 30% of active sessions simultaneously in Redis. Estimate the minimum memory required for the Redis cache, considering 20% overhead for metadata and replication.
Calculate total data size, then add overhead.
30% of 10 million users = 3 million sessions. Each session 2 KB → 6 GB raw data. Adding 20% overhead → 6 GB * 1.2 = 7.2 GB minimum memory.