The internet is fast, but physics is rude. Light in fiber travels at ~200,000 km/s sounds quick, but if your request has to cross oceans, the round trip adds up.
Example:
- Delhi ↔ Virginia (a common AWS region) is ~12,000 km.
- One round-trip TCP handshake = ~150 ms minimum latency.
- Add TLS handshake + fetching the video + congestion → hello, buffering wheel.
That’s why your TikTok can’t come straight from “the origin.” It would be like ordering pizza from New York when you live in Bangalore.
the CDN
A Content Delivery Network (CDN) is a set of geographically distributed servers (called Points of Presence, or PoPs). These servers cache and serve static or semi-static content (videos, images, JS bundles).
Key idea is to put the content closer to users, so data only travels tens of kilometres, not thousands.
Think of it like Domino’s: one recipe (the origin), many local kitchens (the PoPs).
How It Actually Works (Nitty Gritty)
Step 1: DNS Resolution Magic
- You request
video.tiktokcdn.com
. - Your DNS resolver asks the authoritative DNS server.
- Instead of one fixed IP, CDNs return the IP of the closest PoP (using GeoDNS, Anycast routing, or both).
- Result: your device thinks it’s just talking to “TikTok,” but in reality it’s hitting a CDN edge server 20 km away.
Step 2: Cache Behaviour
- CDN edges store content in caches (memory/disk).
- Popular stuff is always hot in cache.
- Cache policy is controlled by headers:
Cache-Control: max-age=3600
→ keep for an hourETag
→ unique fingerprint of file, used for validationVary
→ tell CDN that response depends on certain headers (like language or device type)
Step 3: Smart Transport Optimisations
- TCP termination: Long-haul connections are handled between PoP ↔ origin. The user just connects locally, cutting handshake latency.
- QUIC/HTTP3: Newer CDNs use UDP instead of TCP for faster handshakes and less head-of-line blocking.
- Range Requests: Netflix doesn’t stream the whole 2-hour movie at once your client requests byte ranges (
Range: bytes=500000-999999
). CDNs serve just that slice.
Step 4: Prefetching and Prediction
- TikTok preloads the next 1–2 videos before you swipe.
- Netflix prefetches next segments during playback.
- All of this leans on the CDN so the origin isn’t overloaded.
okay now the literal Netflix vs TikTok (so you don’t get a clickbait title)
Netflix (Open Connect)
- They literally ship custom CDN appliances to ISPs worldwide.
- Popular shows are pre-loaded onto ISP servers.
- Result: when you hit play, packets don’t even leave your ISP’s network.
- That’s why ISPs love/hate Netflix — it saves bandwidth, but Netflix controls the pipeline.
TikTok (Latency-Obsessed)
- Short videos = zero tolerance for buffering.
- Uses aggressive caching and chunked delivery.
- Invests in peering agreements with ISPs so data never travels far.
- Employs AI-driven prefetch: it guesses the next video you’ll swipe to and caches it before you even realise.
Debugging Reality
When something feels “slow,” here’s how engineers peek under the hood:
- Check DNS Resolution
dig video.tiktokcdn.com
→ See which PoP IP you’re resolving to. If it’s another continent, that’s the problem.
2. Check Cache Headers
curl -I https://video.tiktokcdn.com/somefile.mp4
Look for:
x-cache: HIT
→ served from edge (fast)x-cache: MISS
→ fetched from origin (slower)age: 123
→ how long it’s been cached in seconds
3. Trace Latency
traceroute video.tiktokcdn.com
→ If hops stay local, CDN is working. If you see packets crossing oceans, something’s misconfigured.
4. Chrome DevTools
- Look at
Timing
tab on requests. - Long DNS or TCP connection times = you’re hitting a far PoP.
Why This Matters in Real Life
- Your site’s “slow in India” but fine in the U.S.? Probably CDN misconfig, not your code.
- Mis-set cache headers → CDN constantly refetches → user sees lag.
- No CDN at all → you’re paying in both latency and cloud egress $$$.
- Debugging CDN behaviour is often the difference between an app people binge on (TikTok, Netflix) and one they abandon after the loading spinner.
CDNs are the secret sauce of the modern internet. They hide latency, mask origin weakness, and make the web feel instant. Netflix wouldn’t scale without Open Connect. TikTok wouldn’t dominate without their edge strategy.
Without CDNs, the internet would still be buffering like a 2008 YouTube video.