Recently helped a few video station to do architecture optimization, stepping on the pit stepped to doubt life. A father always complained: "Why not spend less money, the user or spit card into the PPT?" After checking the link to find that 90% of the problems in the CDN caching strategy - either the cache breakdown leads to the source station pressure explosion, or the preloading mechanism is a sham.
These days, even CDNs have to "prevent teammates". The default configuration of some service providers is simply bad, not moving back to the source to pull the flow, the source station bandwidth costs soared faster than the rocket. I found that with the right caching strategy can directly cut the bandwidth cost in half, buffer time to reduce 80%. today talk about this set of combinations - segmented caching + preloading, absolutely carry traffic, the ultimate experience of the big move.
First, let's pour cold water: don't believe in those metaphysical propaganda of "one-click full-site acceleration". Video traffic and web pages are not the same thing, sudden traffic, long connection, large file slicing, which can be the traditional caching rules down. I've seen the most outrageous case: a platform with an ordinary CDN cache MP4 files, peak 95% request penetration cache, the source station directly hit downtime. Later found that the CDN nodes are not adapted to the Range request, each client to re-raise the entire video!
Segmented caching is what is needed in the video era. The principle is actually straightforward: cut the video file into a number of small segments (such as HLS's ts segmentation or MP4's moov/mdat structure), and do the cache management and expiration policy according to segment granularity. For example, the first 1 minute of content cached for 24 hours, the middle part of the cache for 2 hours, the end of the cache for 10 minutes - after all, the user jumps the end of the film is the norm.
Taking the HLS protocol as an example, the optimized Nginx configuration would have to be written like this:
Here's the key point.proxy_cache_keyMake sure you bring it.$slice_rangeThis is the step that many Ops miss! Many O&M missed this step, resulting in different Range requests covering each other's caches, instead of triggering confusion. I suggest using the CDN07 family node test, their support for Range requests than some of the major manufacturers are still stable, measured millions of concurrent cache hit rate can be maintained at 92% or more.
Segmentation is not enough, preloading is the killer experience. However, 90%'s preloading solutions are planted on "blind pre-push" - users only watch 10 seconds, and it's a waste of bandwidth to cache the whole movie locally. The optimal solution is to combine user behavior analysis: 5 seconds after the beginning of the movie, the next segment must be preloaded, and the preload window is dynamically adjusted according to the network speed in the middle of the movie. Even downgrade to 144p in a weak network environment to ensure smoothness.
We're sharing the logic of our own preloading algorithm:
Don't underestimate these lines of code, the actual test can press the lagging rate to below 3%. In particular, the edge nodes of the CDN5 family with this strategy, even in the evening peak subway scenarios, you can do a second open + zero buffer.
DDoS attacks like to focus on the video CDN, because the traffic is large and easy to amplify the effect of the attack. It is recommended to bind the authentication parameters to the cache key:
This illegal token request will not return to the source at all, directly in the front-end node is intercepted. Last year with this program to help a live platform to resist 800Gbps CC attacks, the source bandwidth almost no fluctuations.
Brand, a comprehensive comparison of the three: CDN5 has the strongest defense capability, comes with WAF and bandwidth expansion protection, but the price is high; CDN07 intelligent scheduling to do hard, especially overseas nodes latency control is excellent; 08Host belongs to the cost-effective butchers, the domestic BGP line is stable, suitable for small and medium-sized teams with tight budgets. If the pursuit of the ultimate experience, you can engage in mixed scheduling - the key area with CDN5 to carry attacks, overseas users go CDN07, ordinary content dumped to 08Host.
Finally throw a king bomb data: after a short video app with 10 million monthly activities accessed the combination strategy, the bandwidth cost of the source station dropped from 370,000 to 150,000 per month, and the median buffering time dropped from 2.1 seconds to 0.4 seconds. User Satisfaction Improvement? It's enough to see the App Store rating soar from 3.2 to 4.7.
Video optimization is a business that dies quickly on paper. Really want to solve the problem, have to hold the instrument squatting machine room, capture packets to analyze each RTT. those who talk about "global cache" experts, it is recommended to directly throw out - they probably even Range request and Content-Length can not be distinguished.
By the way, some customers have to buy a CDN with "ultra-high protection but no cache" for a cheap price, and then they are shocked by the traffic bill and collapse. Remember, protection and acceleration is a symbiotic relationship, to separate is a rogue.
Go check your CDN configuration now. If you findX-Cache-StatusA sliver of MISS in there, hurry up and dislike segmented caching and preloading. Save enough money to give the team a half year bonus.

