Web Cache - Variations and Follow-up Questions
Common Variations
1. CDN (Content Delivery Network)
Key Differences:
- Global edge locations (100+ POPs)
- GeoDNS routing to nearest edge
- Origin shield for protection
- DDoS mitigation
- SSL/TLS termination at edge
Additional Features:
- Image optimization
- Video streaming
- Real-time purging
- Analytics and reporting
- WAF (Web Application Firewall)
2. API Gateway Cache
Key Differences:
- Cache API responses (JSON/XML)
- Shorter TTLs (seconds to minutes)
- Cache key includes auth tokens
- Rate limiting integration
- Request/response transformation
Challenges:
- Personalized responses
- Authentication handling
- Cache invalidation on data changes
- Versioning support
3. Browser Cache
Key Differences:
- Client-side caching
- Limited storage (50-100MB)
- Cache-Control headers
- Service Workers for offline
- IndexedDB for structured data
Considerations:
- Privacy (no sensitive data)
- Storage limits
- Cache eviction by browser
- HTTPS requirement for Service Workers
4. Database Query Cache
Key Differences:
- Cache query results
- Invalidate on data changes
- Cache key = query + parameters
- Shorter TTLs (seconds)
- Integration with ORM
Challenges:
- Complex invalidation logic
- Join query caching
- Transaction handling
- Consistency guarantees
Interview Follow-up Questions
Q: How do you handle cache stampede?
Answer:
- Request coalescing (single origin fetch)
- Stale-while-revalidate (serve stale, refresh async)
- Probabilistic early expiration
- Cache locking mechanism
Q: How do you invalidate cache across multiple nodes?
Answer:
- Pub/sub for invalidation events
- Broadcast to all nodes
- Eventual consistency (<1s)
- Retry failed invalidations
- Audit log for tracking
Q: How do you handle personalized content?
Answer:
- Include user ID in cache key
- Cache common parts, personalize on edge
- ESI (Edge Side Includes) for fragments
- Vary header for different versions
- Short TTL for personalized content
Q: What happens when origin is down?
Answer:
- Serve stale content (stale-if-error)
- Extended TTL during outage
- Circuit breaker to stop origin requests
- Fallback to backup origin
- Error page if no stale content
Q: How do you measure cache effectiveness?
Answer:
- Hit rate (hits / total requests)
- Byte hit rate (bytes served from cache)
- Origin offload percentage
- Latency improvement
- Cost savings
Q: How do you handle cache poisoning?
Answer:
- Validate origin responses
- Sanitize cache keys
- Limit cache key length
- Ignore suspicious headers
- Rate limit cache writes
- Monitor for anomalies
Q: How do you optimize for mobile clients?
Answer:
- Adaptive compression (lower quality)
- Image resizing and optimization
- Smaller cache entries
- Longer TTLs (limited bandwidth)
- Service Workers for offline
Q: How do you handle large files (videos)?
Answer:
- Range request support
- Chunked transfer encoding
- Progressive caching
- Separate storage tier
- Streaming optimization
This guide covers common variations and helps prepare for deep-dive questions in interviews.