Caching Strategies & In-Memory Optimization Questions
Designing cache layers to cut redundant work and speed up reads, and the correctness costs that come with them. Covers cache placement across client, CDN, application, and in-memory store tiers, including platform-specific caching on mobile (in-memory and disk caches on iOS and Android, secure on-device token storage) and in the browser (localStorage, IndexedDB, Service Workers). Covers eviction policies, TTLs, write-through vs write-back, warming, and invalidation, plus cache stampede and thundering-herd mitigation when a hot key expires under load. Also covers using an in-memory store like Redis directly rather than only as a cache: distributed locks, counters, rate limiters, and leaderboards. Includes distributed and sharded cache architecture (replication, failover, sizing, migration) and the operational side of running one: health monitoring, alerting, and incident runbooks, plus the security and privacy risks caching introduces, such as cache poisoning and caching PII across shared tenants. Emphasizes hit-rate reasoning and the staleness/consistency trade-offs caching introduces.
Design rules for edge cache key composition when requests include query strings and cookies. For example, search endpoints accept ?q= and pagination ?page=, while cookies include session info. Explain which query params should be part of the cache key, how to canonicalize and normalize query strings, how to deal with ordering and irrelevant tracking params, and how to ensure personalization doesn't leak between users.
What is TTL (time-to-live) in caching systems and what role does it play? Discuss trade-offs between short and long TTL values, effects on cache hit rate and backend load, and when you would use sliding TTL (refresh on access) versus fixed TTL. Include examples relevant to Redis or Memcached usage.
You have an API endpoint /product/{id} that pulls product details with joins across multiple tables and each request currently takes ~300ms from the DB. Reads dominate writes (100:1). Describe a practical server-side caching strategy to reduce p99 latency for this endpoint. Include cache key design, TTL considerations, invalidation on updates, and how to handle personalization-sensitive fields like 'is_in_user_wishlist'.
GraphQL APIs often return deeply nested, personalized payloads. Design a caching approach for a GraphQL server that maximizes reuse: describe persisted queries, response fingerprinting, partial-field caching, query whitelisting, cache key strategies (root-level vs field-level), and how you'd handle authorization (Vary behavior).
You observe p99 latency for Redis rising intermittently from 1ms to 50ms. Provide a step-by-step troubleshooting checklist: which Redis stats/commands to run (INFO, SLOWLOG, LATENCY), OS-level metrics (CPU, mem, IO), configuration flags to inspect, and likely causes such as large keys, persistence (RDB/AOF), background saves, fragmentation, or slow commands.
Unlock Full Question Bank
Get access to all Caching Strategies & In-Memory Optimization interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.