• Beijing to Beijing: ~5ms • Beijing to Shanghai: ~35ms • Beijing to Guangzhou: ~50ms • Beijing to Tokyo: ~100ms • Beijing to New York: ~250ms • How to make people all over the world load the webpages amazingly fast? Image: https://en.wikipedia.org/wiki/Content_delivery_network
load times • increasing global availability of content • Covers a lot of types of content delivery services • web objects (text, graphics and scripts) • downloadable objects (media files, software, documents) • on-demand streaming media • live streaming media
CDN servers can simply cache the page • However, it is full of dynamic pages nowadays • Every time you open Zhihu, it is completely different • How can CDN help dynamic pages?
a page • Web server gives you some HTML code • Plain Text, typically small in size • Including content text • Including URL to CSS, Javascript and other resources (images, audios, videos…) • Changes all the time for dynamic pages • Your browser need to fetch all these resources to render the webpage
IP to content server • Local DNS server asks authoritative DNS server • Authoritative DNS server chooses the best CDN server according to the IP address of local DNS sever • CDN server caches content • User fetches content from CDN server
• Easy to scale out • Widely used • Cannot get information other than local DNS IP • may result in inaccurate resolve • have some workarounds, for example, EDNS ref: https://blog.goquxiao.com/posts/2015/11/22/gslb-research-1/
to GSLB • GSLB sends HTTP 302 redirection back to user • High pressure on GSLB server (single point) • HTTP only • Rich user information (IP, browser, language, …) • better resolve result • log down user behaviors • Easier to implement ref: https://blog.goquxiao.com/posts/2015/11/22/gslb-research-1/
occurs, CDN server needs to fetch the resource from the origin server • For small files, this is fast. • For large files, fetching from the origin server may introduce a large latency. • Origin server pushes to CDN servers in advance
pushes to an edge CDN server • CDN servers pushes to each other internally • better network connections between CDN internally • CDN provides larger bandwidth • Subscriber pulls from an edge CDN server Image: https://mp.weixin.qq.com/s
protection strategy • CDN provider may have large enough bandwidth to absorb DDOS traffic • Origin server address can be hidden from Internet, letting only CDN provider knows • May cost large amount of money • Infeasible for many DDOS attacking methods Image: https://blog.cloudflare.com/ddos-prevention-protecting-the-origin/
SSL certificate • *.cloudflare.com • Website directly uses the second level domain given by CDN provider • https://mywebsite.cloudflare.com/static/layout.css Image: http://cleventy.com/paginas-web-seguras-que-es-el-https/
private key to CDN provider • Mainstream solution • Supports custom domain • static.zhihu.com • if the website changes CDN provider, the URL doesn’t need to change • Security concern for a few people • Private key may be leaked from CDN provider • CDN provider knows the content Image: https://www.cloudflare.com/ssl/
a key server which is completely controlled by the CDN client itself • Key server is only used to encrypt / decrypt messages during the handshaking process between a user and a CDN server • CDN client can turn off key servers as soon as it finds CloudFlare was doing something immoral • But CloudFlare can still see the content ref: https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/
dynamic pages itself • CDN helps load static resources • but user still needs to first reach the page itself from the origin server • Interconnection between different ISPs in China is still a big problem • How to speed up dynamic page delivery?
ISPs • has its own AS number • has BGP routers • broadcasts its IPs using Border Gateway Protocol • Place web server at a BGP datacenter • Web server don’t need to worry anything • Routers and the protocol do the hard work • Very expensive ref: http://vpsadd.com/?p=1872
cannot use domain name, instead use IP address directly, CDN cannot help at all. • For example, public DNS service • People all over the world use 8.8.8.8 • How does it keep low latency anywhere? • How does it serve so much traffic?
many different locations • A best route is chosen by BGP • The protocol does the hard work • Not suitable for stateful services • Destination may change • State information may lose • CDN provider may use Anycast ref: https://www.zhihu.com/question/54158268
• DNS • HTTP Redirect • Applications • Small files, large files • Video on demand • Live streaming • Additional Features • DDOS protection • HTTPS support • Alternatives • BGP datacenter • Anycast