Essential System Design: 10 Key Questions and Answers on CDNs

When to use a CDN?

  1. Global Reach: If your website or application has users from all over the world, a CDN can greatly improve your service's speed and reliability. CDNs have servers located globally and they serve content from the server closest to the user, reducing latency and improving load times.

  2. Improved Load Times: A CDN stores a cached version of your website in multiple geographical locations around the world, known as "points of presence" (PoP). When a user requests your site, the CDN redirects the request to the server geographically closest to them. This reduces the distance the data has to travel, thereby reducing latency and improving site load times.

  3. Absorb traffic: CDNs are designed to absorb sudden spikes in web traffic. This is particularly important for websites that experience variable traffic, ensuring your website remains accessible and provides a good user experience even during peak times.

  4. Reduced Bandwidth Costs: CDNs can significantly reduce the amount of data an origin server must provide by caching and optimizing files, thus reducing hosting costs.

  5. Always Online: Increased Content Availability and Redundancy. If one server fails, CDNs can automatically reroute the traffic to the next nearest server. This ensures high availability and reliability, even in the event of a server failure or DDoS attack.

  6. Improved Website Security: CDNs provide a layer of protection against malicious attacks such as Distributed Denial of Service (DDoS) attacks. They also offer SSL/TLS encryption and other security features to ensure data integrity and privacy.

  7. Software Distribution: Companies that distribute software or updates to a global user base can use a CDN to ensure quick and reliable downloads. This is particularly important for operating system updates, antivirus software, and other applications where timely updates are crucial.

  8. Media Streaming: For websites or applications that stream video or audio content, CDNs are vital. They ensure smooth, buffer-free streaming for users, regardless of their location.

  9. Live Events: For live online events like concerts or sports, a CDN can handle the sudden influx of users and provide a seamless viewing experience, free of buffering or lag.

When not to use a CDN:

1. Small Audience or Limited Geographic Reach: If your website's audience is small or primarily located in a single geographic location (near to your hosting server), a CDN may not provide much benefit and might not be worth the cost.

  • A local restaurant's website

    A small restaurant that serves a local community and whose patrons are all from the same city wouldn't benefit much from a CDN. The website's traffic levels would be relatively low, and all visitors would be geographically close to the hosting server.

  • An intranet application for a single office location

    If a company builds an internal application used exclusively by employees at a single office location, a CDN would not offer much advantage. All users are accessing the application from the same location, so the latency benefits of a CDN would not be realized.

2. Dynamic, Non-cacheable Content: CDNs are best at delivering static, cacheable content (like images, CSS, JavaScript, and HTML files). If your site or application primarily serves dynamic, non-cacheable, or personalized content, you may not see a significant performance improvement with a CDN.

  • A financial app dealing with real-time data

    If an app deals primarily with dynamic, real-time data (like a stock trading app), a CDN may not be very beneficial. CDNs are most effective at caching and serving static content, so they might not significantly improve performance for an application like this. In such a scenario, it would be more beneficial to focus on optimizing server performance and database queries.

3. Data Privacy and Compliance: In some cases, strict data privacy regulations or compliance requirements might limit your ability to distribute data across various geographic locations. In such cases, using a CDN may pose regulatory challenges.

  • A healthcare portal with strict data privacy requirements

    To ensure patient data confidentiality, a healthcare portal concerned about data leaks would opt against using a CDN. By relying solely on internal servers and infrastructure, they can maintain strict control over data access and minimize the risk of unintended data exposure that could arise from utilizing a CDN with distributed servers.

Do you know CDN's standard internal infrastructure?

The choice of infrastructure architecture plays a vital role in defining a CDN's product identity and determining the value it brings. At the core of CDN infrastructures are PoPs (points of presence) which are regional data centers responsible for interacting with users in close proximity.

What is PoP house? Typically, each PoP houses multiple servers and routers that handle caching, connection optimization, and other content delivery features. For CDNs that offer security solutions, PoPs also house DDoS scrubbing servers and machines dedicated to other security-related functions.

How to reduce round-trip time, boosting website speed and responsiveness? Regional distribution centers. By utilizing regional content distribution centers, the round-trip time (RTT) is significantly reduced, resulting in a faster and more responsive website for visitors, regardless of their location.

Round-trip time (RTT) refers to the duration, measured in milliseconds (ms), it takes for a browser to send a request and receive a response from a server. RTT is not influenced by file size or internet connection speed but is determined by factors such as physical distances, the number of intermediate nodes, amount of traffic, and transmission mediums. RTT plays a crucial role in determining the speed of rendering in the user's browser, as the rendering cannot commence until the initial request for the HTML file is returned.

What's Alternatives of CDN?

During a system design interview, when seeking ways to enhance website speed and responsiveness, CDN is the first solution that comes to mind. However, there are other alternatives worth considering, such as Carrier-Neutral Data Centers and Mirror Sites. These alternatives can also play a significant role in improving website performance.

CDN vs Carrier-neutral Data Centers?

A carrier-neutral data center is a facility that provides interconnection to multiple third-party network service providers (carriers) and/or internet service providers (ISPs). The carrier neutrality of the facility ensures that clients have a choice of connectivity options, and it encourages competition between the various providers, which can lead to better pricing and service quality for the end-users.

Common carrier-neutral data centers do address the issue of slow access between different ISPs, but this solution requires relinquishing some control and introducing an additional layer of dependency into the system.

However, using a CDN can provide a more flexible and customizable solution. For instance, given that CDN nodes are distributed across a range of ISPs, connection data can be retrieved to ensure better routing. Moreover, the traffic distribution principle of a CDN inherently equips it with the ability to resist network attacks."

CDN vs Mirror Sites?

A mirror site is a replica of an already existing website, containing identical or near-identical content, but hosted on a different server and often under a different domain name.

CDN is entirely transparent to the website's visitors; there's no need for visitors to manually select the mirror site they want to visit, ensuring a friendly user experience. CDN performs availability checks on each node, excluding any nodes that don't meet the standards promptly, thus guaranteeing high availability - something that mirror sites can't achieve. Deploying CDN is simple and generally doesn't require any changes to the original site to take effect.

Does CDN acceleration apply to the server or to its domain name?

CDN accelerates a specific domain name of a website. If a website has multiple domain names, visitors accessing the domain name with CDN will experience the acceleration effect, but those accessing non-CDN domain names, or directly accessing the IP address, will not experience the CDN effect.

How to setup the CDN?

Setting up a CDN is typically a seamless process that can be accomplished with just a few clicks on the dashboard. No modifications are generally required for the origin website to harness the acceleration benefits of the CDN. However, minor adjustments may be necessary for software reliant on visitor IP identification.

Have you ever experienced the issue of outdated data persisting via a CDN even after deploying new content? How to troubleshoot and resolve this issue?

Due to CDN's caching mechanism across various nodes, static webpages and images might remain unchanged if CDN cache isn't updated correspondingly after modifications are made, leading to old webpages being displayed. To resolve this, the CDN provider always provides a URL purge service to notify all CDN nodes to refresh their cache. By entering specific webpage or image addresses in the URL purge bar, cache content on all nodes will be deleted uniformly and take effect immediately. If there are too many URLs and images to purge, directory and regex based purging can be chosen.

Also the CDN caches may at different levels, including the CDN edge servers, the user's browser, and possibly intermediary proxies, can store outdated content and serve it instead of the updated version. To optimize CDN caching, consider two key steps:

  1. Configure cache control headers.

  2. Set CDN TTL properly.

Can CDNs be configured to avoid caching web pages and images that require frequent real-time updates?

Some web pages and images may need to be updated frequently or in real time, such as news articles, stock prices, or live streams. In these cases, caching them on a CDN may result in outdated or inaccurate information being delivered to the users. Therefore, it is possible to configure a CDN not to cache certain web pages and images that require high real-time updates.

This can be done by using HTTP headers, such as Cache-Control or Expires, to instruct the CDN servers how long to store the web content before requesting a fresh copy from the origin server. For example, if a web page contains a live stream of a sports event, it can use the Cache-Control header with the value "no-cache" or "max-age=0" to prevent the CDN from caching it at all. Alternatively, some CDN providers may offer more granular control over the caching behavior, such as allowing the users to specify which URLs or file types to exclude from caching, or using dynamic tokens or signatures to validate the freshness of the web content.

Another option is to leverage Edge Side Includes (ESI) if supported by the CDN. ESI tags allow dynamic inclusion of specific parts within a web page while still benefiting from CDN caching. By isolating frequently updated sections within ESI tags, only those sections bypass caching while the CDN caches the remaining parts of the page, ensuring real-time updates for the specified sections.

Alternatively, one website could use two domain names: one enabled with CDN and the other without, and pages and images requiring real-time updates can be placed under the domain without CDN.

Last updated