Table of contents
TogglePreface
If you are a software engineer, you must be familiar with the term CDN. However, if you carefully explore the principles of CDN and how to design it, it may not be so clear. Therefore, I will first explain the content delivery network (Content Delivery Network). concepts, and how we implement them.
CDN to system design
Before explaining CDN, let us look back at the large-scale system itself. If millions of users around the world are using a system, and our services are deployed in a single data center to satisfy user requests (Request) , so what problems might we have?
High latency
If the physical distance between users, data centers, and servers is too high, latency will increase. If users experience high latency, it is usually not caused by a single reason, but by multiple complex reasons, such as: Transmission Delays, Propagation Delays, Queuing Delays and nodes Nodal Processing Delays. Long-distance data transmission will definitely lead to higher delays. According to our human body perception, we would like the system delay to be less than 200 milliseconds. For Voice over Internet Protocol (VoIP), the delay should not exceed 150 milliseconds, and the video playback platform should not exceed a few seconds of delay. For example: Youtube If each click The video will be delayed for a few seconds and users will be lost.
Data-intensive applications
Data-intensive applications usually require the transmission of large amounts of traffic. Over longer distances, this can be a problem because the network path passes through different types of Internet Service Providers (ISPs). As the number of users increases, this type of problem will multiply or even grow exponentially because the server must provide data to each user individually. In other words, when multiple clients request, the main data center will need to send a large amount of useless data (Redundant Data).
Scarcity of data center resources
When the number of users increases, the computing power and bandwidth of data center resources will become limitations or even bottlenecks. Therefore, system services for millions of users will need to be expanded. However, even if expansion is achieved in a single data center, it may still become a single point of failure (Single Point of Failure) when the data center goes offline due to natural disasters or network connection issues.
What is a CDN?
Content delivery network (CDN) is one of the solutions used to deal with the above problems. First of all, CDN is a group of proxy servers (Proxy Server) placed based on geographical location. Among them, the proxy server is an intermediate server between the client and the server, and the proxy server will also be placed at the edge of the network (Network Edge). Also because the edge of the network is close to the end user, the placement of the proxy server helps to quickly transmit the corresponding data to the user by reducing delays and saving bandwidth. In addition to serving as simple proxy servers, CDNs can also make them more efficient through some settings and operations.
A CDN brings data closer to users by placing a small data center near them and storing copies of the data there. CDN mainly stores two types of data: static and dynamic, and mainly solves the propagation delay problem by bringing the data closer to the user. CDN providers also incur additional costs to provide sufficient available bandwidth and bring data closer to users.
So returning to the previously mentioned question, how does CDN solve the problems of high latency, data-intensive applications, and scarcity of data center resources?
- high latency : The physical installation of CDN is relatively close to the client, so users can obtain corresponding data through CDN, thus reducing physical distance and delay.
- Data-intensive applications: Since the data path only includes the ISP and nearby CDN components, there is no problem in serving a large number of users with a small number of CDN components in a specific area. As shown below, the origin data center only needs to provide data once to the local CDN component, and the local CDN component can provide data to different users independently. No user has to download a copy of their data from the origin server.
- Data center resources are scarce: CDN is used to serve popular content. For this reason, most of the traffic is handled at the CDN rather than the origin server. Therefore, different local or distributed CDN elements share the load on the origin server.
CDN design requirements
in this article Non-functional features of software design – System Design 03 , we also explained functional and non-functional requirements, so since we want to design a CDN, we must first list the functional and non-functional requirements.
Functional Requirements
A CDN can be regarded as a database, so it basically needs the following functions:
- Retrieve: Depending on the type of CDN model, the CDN must be able to receive content from the server.
- Request: The proxy server transmits content according to the user's request, and the CDN proxy server should be able to respond to each user's request.
- Deliver: The server should be able to deliver content to the CDN proxy server.
- Search: The CDN should be able to perform searches on user queries against cached or otherwise stored content within the CDN.
- Update: In most cases, the content comes from the server side, but if we execute a script in the CDN, the CDN should be able to update the content in the peer CDN proxy server in the PoP. Among them, a point of presence (PoP) is a demarcation point, access point or physical location where two or more network or communication devices share a connection.
- Delete: Depending on the type of content (static or dynamic), cached entries should be removed from the CDN server after a period of time.
non-functional requirements
Readers who don’t understand non-functional requirements can watch this article Non-functional features of software design – System Design 03 .
- Performance: One of the most important tasks of CDN is to minimize latency, and it is also the main reason why many developers use CDN.
- Availability: Availability is used to ensure that the system can remain continuously available, so CDN can be used to prevent some system attacks, such as DDoS.
- Scalability: More and more client applications can request data from CDN, so CDN can be systematically expanded.
- Reliability: CDN design must ensure that there is no single point of failure. In addition to failures, a CDN must be designed with high reliability to handle large traffic loads.
CDN system design
Because the CDN design itself is relatively complex, I will quote the illustrations from Grokking Modern System Design to explain the CDN system design in detail. Here we will introduce the components of CDN respectively, and then explain the operating principle of CDN based on the components.
CDN components
CDN (Content Delivery Network) is a distributed network composed of servers all over the world, used to accelerate the delivery of content to users. CDN can improve website performance, reduce latency, and improve user experience.
The following are the main elements of CDN system design:
- Clients:Users request content from the CDN on various clients, such as browsers, smartphones, and tablets.
- Routing System:The routing system is responsible for directing users to the nearest CDN facility. In order to do this, the routing system needs to consider the following factors:
- Content placement
- User requests
- Server load
- Scrubber Servers:Cleaner servers are used to separate good traffic from malicious traffic and prevent attacks. Common attack types include DDoS attacks.
- Proxy Servers: Proxy server provides content to users. Proxy servers often store popular content in RAM to improve performance. The proxy server also receives content from the distribution system.
- Distribution System: The distribution system is responsible for distributing content to the different facilities of the CDN. Distribution systems can use a variety of techniques to distribute content, such as:
- cache
- compression
- streaming
- Origin Servers: The origin server is where the original content is stored. When content is not available on the CDN, users request content from the origin server.
- Management System: Management system used to monitor the performance and health of the CDN. Management systems can collect data on metrics such as latency, downtime, traffic, and error rates.
CDN principle
This CDN process is explained by Grokking Modern System Design:
- The origin server provides the URIs of all objects cached in the CDN to the request routing system.
- The origin server publishes content to a distribution system that is responsible for data distribution across active edge proxy servers.
- The distribution system distributes content between proxy servers and provides feedback to the request routing system. This feedback helps optimize the selection of the closest proxy server for requesting clients. This feedback contains information about what content is cached on which proxy server to route traffic to the relevant proxy server.
- The client requests the appropriate proxy server from the routing system.
- The request routing system returns the IP address of the appropriate proxy server.
- For security reasons, client requests are routed through the cleaner server.
- The scrubber server forwards good traffic to the edge proxy server.
- The edge proxy server serves client requests and periodically forwards accounting information to the management system. The management system updates the source server and sends feedback to the routing system with statistics and details about the content. However, if the content is not available in the proxy server, the request will be routed to the origin server. If content is not found in an edge proxy server, there may also be a hierarchy of proxy servers. In this case, the request is forwarded to the parent proxy server.
Postscript
CDN is a tool commonly used by software engineers. You can also use ready-made CDN services from some Internet service providers. However, it is also recommended that you learn more about the principles behind CDN before using it, which will also help you understand the system design. The next article will also continue to explain CDN related content. Readers who like system design may also wish to watch other content.
related articles
Key-Value Store key-value data storage explanation – system design 11
Data Partitioning What is data partitioning? – System Design 10
How does Data Replication optimize the database? - System Design 09
Introduction to database basics – system design 08
Load Balancer Explained – System Design 07
What is DNS? Introduction to Domain Name System – System Design 06
Introduction to System Design Components Building Block – System Design 05
Back-of-the-envelope Back-of-the-envelope Calculation – System Design 04
Non-functional features of software design – System Design 03
Application of abstraction in system design – System Design 02
Introduction to Modern System Design – System Design 01
Quote
What is a content delivery network (CDN)? | How do CDNs work?