Skip to content

06_Content_Delivery_Networks__Cdn_

Difficulty: Foundational
Generated on: 2025-07-13 02:51:12
Category: System Design Cheatsheet


CDN (Content Delivery Network) - System Design Cheatsheet (Foundational Level)

Section titled “CDN (Content Delivery Network) - System Design Cheatsheet (Foundational Level)”

A Content Delivery Network (CDN) is a geographically distributed network of proxy servers and their data centers. Its purpose is to deliver content efficiently to users, minimizing latency and maximizing availability. It works by caching content closer to the end-user, reducing the distance data needs to travel.

Why is it important?

  • Reduced Latency: Faster content delivery translates to a better user experience.
  • Increased Availability: Content is served from multiple locations, improving resilience to outages.
  • Reduced Origin Server Load: Caching reduces the load on the origin server, improving its performance.
  • Improved Scalability: CDNs handle a significant portion of traffic, allowing the origin server to scale more effectively.
  • Cost Savings: Offloading traffic to a CDN can reduce infrastructure costs.
  • Caching: Storing content closer to the user (at edge servers).
  • Content Routing: Directing user requests to the optimal edge server based on location and network conditions.
  • Content Invalidation: Mechanisms to update cached content when the origin server changes.
  • Origin Server: The source of the content that the CDN caches.
  • Edge Servers: Servers located geographically closer to users that store and serve cached content.
  • Hit Ratio: The percentage of requests served from the CDN cache (higher is better).
  • Time To Live (TTL): The duration for which content is cached on edge servers.

Basic CDN Architecture:

graph LR
A[User] --> B{CDN Edge Server (Closest)};
B -- Cache Hit --> A;
B -- Cache Miss --> C[Origin Server];
C --> B;
B --> A;
style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#ccf,stroke:#333,stroke-width:2px
style C fill:#ccf,stroke:#333,stroke-width:2px

Content Invalidation:

graph LR
A[Origin Server] --> B(Invalidation Request);
B --> C{CDN Control Plane};
C --> D[CDN Edge Servers];
D --> E(Content Purged/Refreshed);
style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#ccf,stroke:#333,stroke-width:2px
style C fill:#ccf,stroke:#333,stroke-width:2px
style D fill:#ccf,stroke:#333,stroke-width:2px
style E fill:#ccf,stroke:#333,stroke-width:2px

When to use a CDN:

  • Static Content: Images, videos, CSS, JavaScript files. This is the most common and effective use case.
  • Large Downloadable Files: Software installers, large documents.
  • Streaming Media: Video and audio streaming.
  • Web Applications with Global Users: Websites and applications serving users worldwide.
  • Protecting Origin Server from DDoS attacks: Many CDNs offer DDoS protection as part of their service.

When to avoid a CDN (or use with caution):

  • Highly Dynamic Content: Content that changes frequently and requires near real-time updates (e.g., stock prices updated every second). Invalidation strategies become critical and complex.
  • Content Requiring Strict Authorization: While CDNs can handle authentication, sensitive data might be better served directly from the origin, especially if complex authorization logic is involved. Consider edge computing solutions in these cases.
  • Small Websites with Limited Traffic: The cost of a CDN might outweigh the benefits for very small websites with low traffic.
  • Content with Very Short TTLs: If the TTL is too short, the CDN acts as a proxy, adding latency instead of reducing it.
ProsCons
Reduced LatencyCost (can be significant for high traffic)
Increased AvailabilityComplexity (configuration, invalidation)
Reduced Origin Server LoadPotential for stale content if invalidation fails
Improved ScalabilityDependency on a third-party service
DDoS ProtectionAdded layer of security to manage
Improved SEO (faster website loading speed)
  • Scalability: CDNs are inherently scalable due to their distributed architecture. They can handle massive spikes in traffic. The CDN provider manages the scaling of edge servers.
  • Performance:
    • Cache Hit Ratio: A higher hit ratio means better performance. Optimize cache settings (TTL) and content delivery strategies to maximize hit ratio.
    • Latency: CDNs significantly reduce latency by serving content from geographically closer servers.
    • Bandwidth: CDNs can handle large amounts of bandwidth, preventing bottlenecks.

Scaling Strategies:

  • Geographic Expansion: CDN providers add more edge locations to improve coverage.
  • Capacity Expansion: Increasing the capacity of existing edge servers (bandwidth, storage).
  • Content Optimization: Optimizing content size (e.g., image compression) to reduce bandwidth usage.
  • Netflix: Uses its own CDN (Open Connect) to deliver video content globally. They strategically place Open Connect Appliances (OCAs) within ISPs’ networks.
  • Facebook: Uses a CDN to deliver static assets (images, CSS, JavaScript) and also caches dynamic content using edge computing.
  • Google: Uses Google Cloud CDN to deliver content for its various services, including YouTube, Google Cloud Storage, and websites hosted on Google App Engine.
  • Amazon: Uses Amazon CloudFront to deliver content for its e-commerce platform, streaming services (Prime Video), and other services.
  • Akamai: A major CDN provider used by many large companies for content delivery, security, and web performance optimization.
  • What is a CDN and how does it work? (Basic definition and architecture)
  • What are the benefits of using a CDN? (Latency, availability, scalability, etc.)
  • When would you use a CDN? When would you not use one? (Use cases and limitations)
  • How does content invalidation work in a CDN? (Push vs. Pull invalidation, TTL)
  • What is a cache hit ratio and why is it important? (Definition and impact on performance)
  • How do you choose a CDN provider? (Factors like cost, features, global coverage, support)
  • What are some strategies for optimizing CDN performance? (Caching, compression, TTL management)
  • How does a CDN handle dynamic content? (Caching strategies, edge computing)
  • How does a CDN improve security? (DDoS protection, SSL/TLS encryption)
  • Design a system to deliver images globally with low latency. How would you use a CDN? (Open-ended design question)
  • Explain the differences between Origin Pull and Origin Push CDN configurations.
  • What are the challenges of using a CDN for frequently updated content?

This cheatsheet provides a foundational understanding of CDNs. Remember to tailor your answers in interviews to the specific context and requirements of the problem. Good luck!