What is a CDN?
A content delivery network (CDN) is a bunch of servers distributed across the world which work together to provide fast delivery of internet content.
Why use a CDN?
Performance
- Research from fastly shows 20% of visitors leave the website if the page load time is slower than 5 seconds.
- CDNs help you combat the laws of physics. Do whatever you want even if you combat all latency, the max theoretical speed you can serve data is the speed of light so. At the speed of light, in reality it takes 200ms to serve content from London to Sydney. The answer to this is to reduce the distance and cache locally.
- Time = Distance / Speed
- 0.053s (53 milliseconds) = 10,000 (Distance from London to Sydney) / 186,000 (speed of light in miles per second).
- That’s a straight line and does not account for light traveling through fiber (120,000 mps). The reality is it take approx 200ms.
- CDN is only good for static content right? Mostly yes but CDNs can be used to speed up serving of dynamic content. How? Let’s imagine out customers are 200ms away from origin. SYN + SYNACK + TLS HS + TLS HS + Request + Response will take 200 * 6 = 1.2s. Use a CDN and all those times can be cut down to 20ms (20*6=120ms) and then the CDN would need to forward the request to origin for the dynamic content (200+120=320ms). Public API calls can be cached!
Security
- Layer 3/4 DDOS protection
- UDP/ICMP/SYN
- Layer 7 DDOS protection
- Inspect HTTP traffic
- Block/Redirect
- Instant visibility in edge traffic
- Edge firewall rules
Availability
- Unplanned spikes in traffic due to due to a social or political event, say a x10 increase in traffic. This can knockout a system as the system probably wasn’t designed to handle that kind of sudden spike. Even if you have auto-scaling enabled it would not be able to respond in the short time frame needed. Consider a CDN.
- If your origin goes offline the CDN can keep serving whatever they had cached and the end user wouldn’t notice the outage.
- CDN infrastructure is build more resilient. For example CDNs have may ISPs this enables them to route around problems on the internet. They can also choose the best path between the customer and the CDN and the CDN and the origin.
Cost
Most CDNs charge for their services, but the savings on monthly data transfers will typically outweigh the cost of using the CDN.