Caching medium
Your API response includes `Vary: User-Agent`. What is the likely negative capability impact on intermediate caches (CDNs)?
- A It significantly enhances data security by effectively encrypting the response content based on the user's specific browser version.
- B It fragments the cache significantly; widely varying User-Agent strings mean many users get redundant cache entries, reducing the hit ratio.
- C It forces the intermediate CDN nodes to perform on-the-fly GZIP or Brotli compression for every individual request to minimize bandwidth.
- D It has no measurable performance impact, as modern CDNs are designed to ignore the Vary header in favor of their own internal hashing logic.
Answer: B. It fragments the cache significantly; widely varying User-Agent strings mean many users get redundant cache entries, reducing the hit ratio.
The `Vary: User-Agent` header tells caches to store a separate copy of the response for *every unique User-Agent string*. Since standard User-Agent strings contain versions, OS details, and minor differences, this leads to **Cache Fragmentation**. The same content is stored thousands of times, and the Hit Ratio drops precipitously because few users share an identical UA string.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In the Cache-Aside pattern, what happens when the application requests data that is missing from the cache (a 'Cache Miss')?
- Why use a centralized Distributed Cache (like a Redis Cluster) over local in-memory caches on each web server?
- Setting a short TTL (e.g., 60 seconds) on a cached object helps to:
- What is the primary architectural goal of introducing a cache into a system?
- Most caching systems rely on the principle of 'Temporal Locality', which states:
- Your cache uses an LRU (Least Recently Used) eviction policy. When the cache is full, which item is removed?