Understanding Content Delivery Networks

Sep 3, 2024

Lecture on Content Delivery Networks (CDNs)

Introduction

  • Problem: Website load time varies by location (e.g., US vs. China).
  • Solution: Strategies like CDNs minimize request latency, crucial for global systems design.

What are CDNs?

  • Definition: CDNs are networks that distribute and deliver content globally.
  • Purpose: Reduce latency by caching static assets closer to users.
  • Components:
    • Servers spread globally.
    • Cache static assets like images, videos, HTML, CSS, JavaScript.

Benefits of Using CDNs

  • Latency Reduction: Users fetch assets from nearby CDN rather than distant origin servers.
  • Bandwidth Savings: Large files (e.g., HD images) use less network bandwidth.

Popular CDNs and Providers

  • Cloudflare CDN
  • AWS CloudFront
  • GCP Cloud CDN
  • Azure CDN
  • Oracle CDN

How Do CDNs Work?

  • Structure: Globally distributed servers with local caches.
  • Cache Synchronization: All caches should be up-to-date.

Types of CDNs

  1. Push CDNs
    • Engineers push files to CDN.
    • Pros: Ensures assets are up-to-date.
    • Cons: More engineering effort.
  2. Pull CDNs
    • Caches updated lazily upon request.
    • Pros: Less maintenance required.
    • Cons:
      • Cache staleness after asset updates.
      • First request latency due to fetching from origin.
    • Popularity: Pull CDNs are more common due to ease of maintenance.

Reducing Cache Staleness

  • Timestamping: Cache with expiry times (default often 24 hours).
  • Cache Busting: Use unique hashes or E-Tags for asset versions.

When Not to Use CDNs

  • Regional Target: No benefit if users are region-specific.
  • Dynamic/Sensitive Assets: Avoid stale data (e.g., financial/government services).

Example Use Case

  • Interview Question: How would a CDN fit in Amazon’s product listing service?

Conclusion

  • CDNs are crucial for reducing latency of static files, but not suited for all scenarios.
  • Evaluate the use case (e.g., user region, asset type) before implementing CDNs.