How does a CDN work, and what should you consider when caching content with one?
What the interviewer wants to hear
- Edge locations cache copies of content close to users
- Cache hit serves from edge; miss goes to the origin
- TTLs and Cache-Control headers decide how long content stays
- Cache key design and invalidation or versioned file names
- Do not cache private or user-specific responses by mistake
Model answer
A CDN has many edge locations around the world. When a user requests a file, DNS sends them to a nearby edge. If the edge has a cached copy, it returns it at once, which is a cache hit; if not, it fetches from the origin, such as an S3 bucket or load balancer, stores it and returns it. This lowers latency and takes load off the origin. The main things I think about are TTLs and Cache-Control headers, which decide how long content is kept, and the cache key, because including unnecessary headers or cookies kills the hit ratio. For updates I prefer versioned file names like app.3f2a.js over frequent invalidations. Finally, I make sure personalized or private responses are marked no-store or private so the CDN never serves one user data to another.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Cloud Engineer questions
- Explain the difference between IaaS, PaaS and SaaS with an example of each.
- What is a VPC and what are its main building blocks?
- Explain IAM users, groups, roles and policies. When would you use a role instead of a user?
- How would you make a simple web application highly available in the cloud?
- What pricing models do cloud providers offer for compute, and when would you use each?
- What is the difference between containers and virtual machines, and when would you choose each?
- What is Infrastructure as Code and why do teams use it instead of the cloud console?
- Explain metrics, logs and traces. How does each help you run a cloud application?
- Compare block, object and file storage in the cloud. Give a use case for each.