CDN (Content Delivery Network) In System Design | SDE Interview

Ganesh Prasad
8 min readJan 16, 2023

--

A Content Delivery Network (CDN) is a distributed server system to deliver content to users. A CDN aims to improve the performance and scalability of delivering content to users by caching and distributing content across multiple locations.

A CDN works by caching frequently requested content, such as images, videos, and web pages, on servers at strategic points worldwide. When a user requests a piece of content, the CDN will check to see if the content is already cached on a server that is geographically close to the user. If the content is cached, the CDN will deliver it to the user, reducing the time it takes to deliver the content and the load on the origin server.

Additionally, a CDN also improves the scalability of delivering content by distributing the traffic across multiple servers. This allows the CDN to handle high traffic and reduce the risk of overloading a single server or service.

CDNs are a key technology used to improve the performance and scalability of delivering content to users by caching and distributing content across multiple locations. They allow for faster content delivery, reduce the load on the origin servers, and improve the scalability of handling high traffic.

Source: digitalocean

How CDNs Works (use of edge servers & role of DNS)

CDNs work by caching content on a network of edge servers strategically placed at various locations worldwide. The edge servers are designed to be as close as possible to the end users so that the content can be delivered quickly and efficiently.

When a user requests a piece of content, the CDN’s Domain Name System (DNS) routes the request to the nearest edge server. The DNS is configured to resolve the hostname of the origin server to the IP address of the nearest edge server. The edge server checks to see if the requested content is already cached. If the content is cached, the edge server delivers the cached content to the user. If the content is not cached, the edge server retrieves it from the origin server and caches it for future requests.

Edge servers are also used to offload traffic from the origin server, which means that the origin server can handle less traffic, improving the system's scalability. Edge servers also provide additional security, load balancing, and compression functionalities.

CDNs also use various techniques, such as caching policies, compression, and minification, to further optimize user content delivery.

Types of Content that can be delivered using CDN

A content delivery network (CDN) can deliver a variety of types of content, including:

  • Text: HTML, CSS, and JavaScript files
  • Images: JPEG, PNG, and GIF files
  • Video: MP4, AVI, and WMV files
  • Audio: MP3, WAV, and AAC files
  • Application files: JavaScript, CSS, and JSON files
  • Streaming content: Live and on-demand video streaming.
  • Dynamic content: generated by CMS, PHP, or other server-side scripts

HTTP, HTTPS, and HTTP/2 For CDN

CDNs use various protocols to deliver content to users, including:

  • HTTP (Hypertext Transfer Protocol): The most common protocol for delivering web content. HTTP is a request-response protocol that allows clients to send requests to servers and receive a response in return.
  • HTTPS (HTTP Secure): A secure version of HTTP that encrypts the data sent between the client and the server. This is typically used to protect sensitive information such as login credentials or financial data.
  • HTTP/2 (HTTP version 2): A newer version of HTTP that aims to improve performance by reducing the number of round trips required for a client to receive content and allowing multiple requests to be sent over a single connection.
  • QUIC (Quick UDP Internet Connections) is a transport layer protocol that uses the User Datagram Protocol (UDP) instead of the Transmission Control Protocol (TCP) to establish secure connections between the client and the server. It’s designed to improve the performance of web applications by reducing the latency of the connection setup.

Some CDNs also support other protocols, such as FTP (File Transfer Protocol) for file delivery and RTMP (Real-Time Messaging Protocol) for streaming video.

The Use of CDNs (e-commerce, media and entertainment, and games)

CDNs are widely used in various applications to improve performance and deliver content to users more efficiently. Some examples include:

  • E-commerce: CDNs can be used to deliver product images, videos, and other multimedia content to users quickly and with minimal latency. This can help improve the user experience and increase conversion rates.
  • Media and Entertainment: CDNs are commonly used to deliver video and audio content, such as movies, TV shows, and music, to users. This can reduce buffering and improve the overall quality of the streaming experience.
  • Online Gaming: CDNs can be used to deliver game assets, such as textures, audio files, and other resources, to users quickly. This can reduce loading times and improve the overall gaming experience.
  • Social Media: CDNs are used to distribute images, videos, and other multimedia content uploaded by users. This helps reduce the server load and improve the user experience.
  • Healthcare: CDNs can be used to distribute medical images and other sensitive data to remote locations quickly and securely. This can help to improve the speed and accuracy of diagnoses and treatment.
  • Finance: CDNs can be used to deliver financial data, such as stock prices and trading information, to users quickly and securely. This can improve the speed and accuracy of financial transactions.

These are just a few examples of how CDNs can be used in different applications. CDNs are versatile and can also be used in many other types of applications.

The use of CDNs to mitigate DDoS attacks and how CDNs can enhance the security of a website or application.

CDNs can be used to mitigate Distributed Denial of Service (DDoS) attacks by distributing traffic across multiple servers and filtering out malicious traffic.

Source: Alibaba

When a DDoS attack occurs, the targeted website or application may receive a large amount of traffic from multiple sources, which can cause it to become unavailable to legitimate users. CDNs can mitigate this by distributing the traffic across multiple servers, which helps to absorb the increased traffic and keep the website or application available.

CDNs can also use various techniques to filter out malicious traffic, such as IP blocking, rate limiting, and traffic shaping. IP blocking can be used to block traffic from known malicious IP addresses, rate limiting can be used to limit the amount of traffic that can be received from a single IP address, and traffic shaping can be used to prioritize legitimate traffic over malicious traffic.

CDNs can also enhance the security of a website or application by providing additional security features such as SSL/TLS encryption, DDoS protection, and Web Application Firewall (WAF) to protect against common web-based attacks such as SQL injection and cross-site scripting.

By using a CDN, the origin server is also protected from DDoS attacks; this is because the CDN servers act as a shield and absorb most of the traffic. This way, the origin server resources are well-spent on handling the malicious traffic, and the legitimate traffic can reach the origin server.

Overall, CDNs can help to improve the performance and security of a website or application by distributing traffic and filtering out malicious traffic, as well as providing additional security features to protect against common web-based attacks.

Some examples of CDN Providers

  • Akamai: One of the largest and most well-known CDN providers, Akamai has a global network of servers and offers a wide range of features, including DDoS protection, SSL/TLS encryption, and Web Application Firewall (WAF). They also have specialized solutions for the gaming, media, and software delivery industries. They have a long history of providing high-performance services, which can be quite expensive.
  • Cloudflare: Cloudflare is another large and well-known CDN provider that offers a wide range of features, including DDoS protection, SSL/TLS encryption, and a Web Application Firewall (WAF). They also offer free and paid plans. They are known for their easy-to-use interface, excellent performance, and pricing. They also have a range of security features, such as rate limiting and bot management.
  • Amazon CloudFront: Amazon CloudFront is a CDN service provided by Amazon Web Services (AWS). It is integrated with other AWS services, such as S3 and EC2, and can be used to distribute content globally. It offers features like DDoS protection, SSL/TLS encryption, and Web Application Firewall (WAF). CloudFront also has a global network of Edge locations that are used to cache and distribute content. This option can be cost-effective and integrated with other AWS services.
  • Fastly: Fastly is a CDN provider that is known for its high-performance and low-latency services. They have a global network of servers and offer a wide range of features, including DDoS protection, SSL/TLS encryption, and Web Application Firewall (WAF). They also offer real-time content purging and advanced caching options, which can be helpful in dynamic websites.

Conclusion

Content Delivery Networks (CDNs) are essential to modern system design. They are used to improve the performance and security of websites and applications by distributing traffic and filtering out malicious traffic. CDNs can also provide additional security features such as SSL/TLS encryption, DDoS protection, and Web Application Firewall (WAF) to protect against common web-based attacks.

Many different CDN providers are available, each with unique features and capabilities. Akamai, Cloudflare, Amazon CloudFront, and Fastly are popular providers offering a wide range of features and services. To find the best fit for your specific needs, it’s essential to research and compares different options.

Overall, using CDNs in system design can significantly improve the performance and security of a website or application and is an essential consideration for any modern system design.

Thanks 🤗.

Do you want to Hire/Connect? LinkedIn | My Portfolio

P.S.: If you like this uninterrupted reading experience on this beautiful platform of Medium.com, consider supporting the writers of this community by signing up for a membership HERE. It only costs $5 per month and helps all the writers.

A clap would be highly appreciated if you liked what you just read. You can be generous in clapping; it shows me how much you enjoyed this story. And if you didn’t like it? Please do comment😋!

--

--

Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart