CDN in System Designing

medium · System Designing

A CDN (Content Delivery Network) is a globally distributed network of proxy servers (called Edge Servers or Point of Presence - PoP ) designed to deliver static and cached digital assets to users as fast as possible. By offloading traffic from your main backend server (the Origin Server ), a CDN forms a critical line of defense in high-traffic system architectures. 1. How a CDN Works (The Geography Factor) When a user requests a static asset (like an image or a JavaScript bundle) from a website without a CDN, the request must travel all the way to the origin server, regardless of physical distance. If your origin is in Virginia, USA, and the user is in London, UK, the data packets must cross the Atlantic, causing high network propagation latency. With a CDN integrated into your system: The user requests https://example.com/logo.png . The DNS system routing resolves the request to the geographically closest CDN Edge Node instead of your origin server. If the edge server has a cached copy of the image (a Cache Hit ), it returns it to the user instantly over a local connection. If the edge server does not have the image (a Cache Miss ), it pulls the asset from the origin server, returns it to the user, and caches it locally for all subsequent nearby users. 2. Core Benefits to the Architecture Drastic Latency Reduction: Because data travels a fraction of the distance over the wire, the round-trip time (RTT) drops significantly, resulting in lightning-fast page load speeds. Reduces Origin Server Load: Up to 80–90% of requests for static web assets can be entirely absorbed by the CDN edge. This prevents your primary backend servers from wasting CPU cycles and bandwidth serving images or CSS files, freeing them up to handle complex dynamic API requests. DDoS Protection and Scalability: Because CDNs are built to handle massive bandwidth, they act as a shield. If your application faces a sudden viral traffic spike or a malicious Distributed Denial of Service (DDoS) attack, the distributed edge network absorbs the hit, keeping your core infrastructure safe. 3. Dynamic vs. Static Content Delivery While CDNs are traditionally known for static assets, modern CDNs can optimize different content types: Asset Type Examples CDN Optimization Strategy Static Content Images ( .png , .jpg ), JavaScript files, CSS styles, video chunks (HLS). Cached heavily at the edge node using long TTLs (Time-to-Live). It rarely changes. Dynamic Content User profile feeds, real-time checkout balances, custom API JSON data. Cannot be safely cached because it changes per user. Instead, the CDN uses Dynamic Site Acceleration (DSA) —keeping persistent optimized TCP routes open back to the origin to fast-track packet delivery. 4. Cache Invalidation: Pull vs. Push Managing how content gets onto the CDN is split into two primary operational models: Pull Zone (Lazy Loading): You upload assets to your origin server. When a user requests it, the CDN "pulls" it automatically on the first cache miss. This requires minimal maintenance. Push Zone: Your build pipeline or application code explicitly uploads ("pushes") assets directly to the CDN storage bucket before users ever ask for them. This is ideal for large file distributions, like mobile app updates or software patches. Handling Updates (Invalidation): If you update a CSS file, but the CDN has cached it for 24 hours, your users will see a broken layout. You fix this using Cache Busting : Instead of overwriting style.css , your build system names it style.v2.css or adds a hash style.abc123.css . Because the filename is completely new, it forces a clean cache miss at the CDN, updating the user instantly without waiting for a TTL to expire.

Back to System Designing

Browse all study material on Careeroza