Caching Senior
What are virtual nodes in consistent hashing and what problem do they solve?
Select the correct answer
Multiple ring positions per physical node, spreading keys more evenly across nodes
In-memory shards that store the hash ring metadata separately from the actual data
Backup replica nodes that take over only when a primary physical node fails completely
Temporary nodes added during rehashing to cache keys while the ring rebalances fully
Why is the choice of serialization format (JSON vs. Protobuf vs. Binary) important when designing a high-performance caching layer?
Select the correct answer
It determines payload size and encode/decode speed, affecting latency and throughput
It decides which eviction policy the cache uses to remove old entries from memory
It controls how cache keys are hashed and distributed across the cluster of nodes
It defines the network protocol used between clients and the distributed cache servers
Explain the 'Dual Write' problem. How do you ensure the cache and database don't get out of sync during an update?
Select the correct answer
Reading from two caches returns stale data; fix it by always querying the primary node.
Writing the same key twice wastes memory; resolve it by deduplicating keys on each insert.
Writing to two replicas at once causes deadlocks; resolve it by locking both rows first.
Updating cache and DB as two steps risks inconsistency; invalidate the cache on writes.
Why might you prefer moving caching logic into a library or sidecar (Read-Through) rather than handling it manually in your application code?
Select the correct answer
It eliminates the need for any eviction or expiration policies at all.
It always lowers latency by caching the data on local disk storage.
It guarantees strict consistency between the cache and the database.
It centralizes cache logic so services avoid duplicating fragile code.
In a cache-aside pattern, on a write should you update the cache or delete (invalidate) the entry? Why is deleting often safer?
Select the correct answer
Delete it, because updating a cache is impossible in cache-aside designs.
Delete it, since invalidation avoids serving stale data after write races.
Update it, because deletion forces an expensive full table reload each time.
Update it, since rewriting always keeps the cache and database in sync.
What is a 'healthy' cache hit ratio, and if your ratio is low, what specific architectural issues or traffic patterns would you investigate?
Select the correct answer
Typically above 90%; if low, examine cache size, key cardinality, and TTLs.
Always exactly 100%; if low, the underlying cache hardware is surely failing.
Around 10% normally; if low, just raise TTLs and ignore the traffic patterns.
Typically below 50%; if low, disable caching entirely to conserve memory use.
Explain the concept of the 'Clock' or 'Second Chance' eviction policy. How does it approximate LRU with less overhead?
Select the correct answer
It scans a circular buffer using a reference bit to skip recently used pages.
It evicts pages strictly in insertion order regardless of any later accesses.
It counts the access frequency per page and evicts the least used one of all.
It tracks exact access timestamps to evict the strictly oldest accessed page.
What is the 'Belady's Anomaly' in the context of FIFO cache eviction?
Select the correct answer
Frequently accessed pages get evicted before rarely accessed ones in LFU.
Removing cache slots can paradoxically decrease the miss rate under LRU.
Cache hit rate stays constant no matter how many slots FIFO is given here.
Adding more cache slots can increase the miss rate under FIFO eviction.
How does an ARC (Adaptive Replacement Cache) attempt to improve upon standard LRU?
Select the correct answer
It doubles the cache size automatically whenever the hit ratio drops too low.
It evicts by frequency only, ignoring recency to favor long-term popular keys.
It replaces timestamps with a single reference bit to reduce tracking overhead.
It balances recency and frequency lists, adapting their sizes to the workload.
What is the 'Two-Segment' or 'LRU-K' algorithm, and why might it be better than standard LRU for certain workloads?
Select the correct answer
It splits the cache into two equal halves and evicts from whichever half is currently larger.
It tracks only the single most recent access and always evicts the newest item that was added.
It remembers the Kth-most-recent access of each item so one-time scans don't evict hot data.
It uses two random samples on each eviction to approximate LRU with far less metadata overhead.
What is the difference between 'Strong Validation' (ETags) and 'Weak Validation' in HTTP caching?
Select the correct answer
Strong validation uses Last-Modified timestamps; weak validation uses hashed ETag values
Strong validation requires byte-for-byte identical resources; weak validation allows semantically equivalent ones
Strong validation works only over HTTPS; weak validation operates on plain HTTP connections only
Strong validation allows semantically equivalent resources; weak validation requires byte-for-byte identical ones
What is 'Refresh-Ahead' caching, and how does it help in reducing tail latency?
Select the correct answer
It delays refresh until after expiry, serving stale data while a background job recomputes it
It proactively refreshes frequently-accessed entries before expiry so reads avoid waiting on recompute
It pre-loads the entire dataset into cache at startup to avoid all runtime database queries
It refreshes every entry on a fixed schedule regardless of access, eliminating all cache misses
What is a Cache Stampede, and how does request coalescing or locking prevent multiple concurrent requests from recomputing the same expensive value?
Select the correct answer
Many requests miss at once and recompute the same value; coalescing lets one compute while others wait
Expired keys accumulate and exhaust memory; coalescing merges them into one entry to free space quickly
A single request floods the cache with writes; locking blocks all reads until the write completes safely
Concurrent requests overwrite each other's writes; locking serializes the writes to keep data consistent
How do you identify and handle a hot key (a single key receiving disproportionately high traffic) in a distributed cache to prevent a single node from becoming a bottleneck?
Select the correct answer
Replicate the key across multiple nodes or add a local in-process cache to spread the load
Shard the key by hashing its value so each request lands on a different random node
Delete the hot key periodically to force the traffic back to the database tier instead
Increase the key's TTL indefinitely so it is recomputed less often on the overloaded node
What is the difference between a cache avalanche and a cache stampede?
Select the correct answer
Avalanche is the cache cluster losing a node and remapping keys; stampede is clients retrying failed reads faster than the DB can serve.
Avalanche is stale data served after expiry; stampede is the database returning duplicate rows when several caches refresh themselves together.
Avalanche is requests for keys that never existed reaching the DB; stampede is a single client sending too many requests in a short burst.
Avalanche is many different keys expiring together overwhelming the DB; stampede is many requests rebuilding the same expired key at once.
How does a Bloom filter actually work, and why are false positives (but not false negatives) acceptable when using it to guard a cache?
Select the correct answer
It hashes items into a shared bit array; a false positive only triggers a needless lookup, but a false negative would skip existing data.
It keeps a counter per key in memory; a false positive slows writes slightly, but a false negative would let duplicate keys be inserted twice over.
It compresses keys into hashed buckets on disk; a false positive returns stale data, but a false negative would permanently lose a cached value.
It stores full keys in a sorted tree; a false positive wastes memory, but a false negative would corrupt the cache by overwriting valid entries.
What is 'Multi-level Caching' (L1/L2 application caches), and how do you manage the complexity of multiple layers?
Select the correct answer
It splits one cache into read and write halves on separate hosts; complexity is managed by syncing them with periodic full reloads.
It tiers caches purely by key size rather than speed or scope; complexity is managed by hashing each key to the correct storage tier.
It pairs a fast in-process L1 cache with a larger shared L2 cache; complexity is managed by coordinating invalidation across layers.
It runs two identical distributed caches in parallel for redundancy; complexity is managed by routing every single read to both layers.
What is 'Near Caching' and how does it leverage both local and distributed layers?
Select the correct answer
It places the cache physically near the database server, letting queries skip the network hop to the application tier.
It routes every request first to the distributed cache, falling back to a local cache only when the remote nodes are offline.
It keeps a small local copy of hot entries in the app, backed by a distributed cache that holds the full shared dataset.
It keeps the entire dataset in app memory only, using the distributed cache solely as a write-behind durable backup store.
In a distributed system, how do you ensure cache coherence across different geographical regions?
Select the correct answer
Use synchronous writes to every region on each update, guaranteeing strong consistency with no added cross-region read latency.
Disable all regional caches and read directly from one global database, ensuring coherence at the cost of much higher latency.
Pin each user permanently to one region's cache only, so coherence never matters because data is never shared across regions.
Use asynchronous replication and invalidation messages between regions, accepting eventual consistency for cross-region reads.
Explain the 'Cache Coherence' problem when using local caches across multiple application instances.
Select the correct answer
A single shared cache locks all instances during writes, blocking reads until updates complete.
Instances overwrite each other's cache entries because they share one memory address space.
Local caches grow unbounded across instances, eventually exhausting memory on every node.
Each instance keeps its own cache copy, so an update on one leaves others serving stale data.
If your system requires strong consistency, can you still use a cache, and what are the trade-offs in latency if you do?
Select the correct answer
Yes, and there is no latency cost because strong consistency removes the need to ever check sources.
No, caching always breaks strong consistency since cached values can never be kept current at all.
Yes, but you must invalidate or validate on each write, adding latency from synchronous coordination.
No, strong consistency requires disabling all reads from memory and serving only from the primary store.
How do you propagate cache invalidation across multiple distributed cache nodes or application instances (e.g., via pub/sub or broadcast messages)?
Select the correct answer
Rely on each node's TTL alone, since broadcasting messages cannot reach all instances reliably.
Have every node poll the database on each read to detect and discard any entries that changed.
Publish an invalidation message on a pub/sub channel so each node evicts the affected key.
Restart every cache node in sequence so they reload fresh values directly from the source store.