Opscraft
Caching & CDNs · Lesson 6 of 6 · 4 min read

Interview questions and model answers

"Explain no-cache vs no-store."

no-cache allows a cache to keep the response but requires it to revalidate with the origin before each use, usually getting a cheap 304 if nothing changed. no-store forbids storing the response anywhere and is what you use for sensitive data. People often use no-cache when they mean no-store.

"How do you deploy a new front-end version without users seeing stale files?"

Fingerprint assets with a content hash in the filename and cache them for a year as immutable, while keeping the HTML on a short TTL. Upload new assets first, then the HTML that references them, and keep old assets around for a while. Then no invalidation is needed except for the HTML, and browsers pick up new files on the next page load.

"A user reports seeing someone else's account page. What happened and how do you fix it?"

Most likely a shared cache, the CDN or a proxy, stored a personalised response because it lacked private or no-store, or because the cache key ignored the session cookie. Immediately invalidate the affected paths and set the endpoints to bypass caching, then review cache behaviours to allowlist only public paths and default everything else to no-store. Treat it as a security incident since data was exposed.

"What is a cache stampede and how do you prevent it?"

When a popular key expires, many concurrent requests miss together and all hit the database, which can take it down. Prevent it by letting only one request rebuild the value with a lock, serving the stale value while it refreshes, refreshing hot keys before they expire, and adding jitter to TTLs so many keys don't expire at once.

"Cache-aside vs write-through?"

In cache-aside the application checks the cache, loads from the database on a miss and stores it with a TTL; it's simple and only caches what's read, but data can be stale until expiry. Write-through writes to the cache and database together, keeping the cache fresh at the cost of slower writes and caching data that may not be read. Most systems use cache-aside and delete the key on update.

"How does CloudFront decide whether two requests are the same?"

By the cache key, which is defined in the cache policy: the host and path plus any headers, cookies and query strings you include. Everything else can still be forwarded to the origin via the origin request policy without affecting caching. Keep the key as small as possible for a good hit ratio, but include anything that changes the response.

"Your Redis cache restarted and the database fell over. What would you change?"

Treat the cache as disposable: run replicas with automatic failover so a node loss doesn't empty it, add TTL jitter and warming for critical keys, put a lock or request coalescing in front of rebuilds, and protect the database with connection limits and load shedding so it degrades instead of failing. Capacity-plan the database for some level of cache misses.

"Why put a CDN in front of an API at all?"

Even if few responses are cacheable, a CDN terminates TLS close to users, reuses warm connections to the origin, absorbs DDoS traffic, hosts the WAF and rate limiting, and can cache the public, slow-changing endpoints such as catalogues or configuration with short TTLs and stale-while-revalidate.