Explain ETag vs Last-Modified.
ETag and Last-Modified are HTTP cache validators: ETag is a unique identifier for a resource’s version, while Last-Modified indicates the timestamp of its most recent update.
When to Use
Use ETag when content changes frequently or with high precision (e.g., dynamic APIs). Use Last-Modified for static files where second-level accuracy is sufficient.
Example
A chat app serving fast-changing messages should use ETags, while a static blog image can rely on Last-Modified headers.
Want to strengthen your interview prep? Explore Grokking JavaScript Fundamentals, Grokking the System Design Interview, or practice with Mock Interviews with ex-FAANG engineers to get real-world guidance.
Why Is It Important
Validators prevent unnecessary data transfers by letting servers respond with 304 Not Modified, saving bandwidth and improving response times.
Interview Tips
Define both clearly: ETag = content version ID, Last-Modified = timestamp. Mention granularity differences and illustrate with a short example (dynamic API vs static file). This demonstrates both technical and practical understanding.
Trade-offs
ETag: Highly accurate but requires server computation and consistency across clusters. Last-Modified: Lightweight but limited to 1-second resolution and may refresh unnecessarily if timestamps change without actual content updates.
Pitfalls
Misconfigured ETags in distributed systems can break caching if different servers generate different tags. Last-Modified may give false positives when file metadata changes but the content remains the same.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78