@jialin.huang
FRONT-ENDBACK-ENDNETWORK, HTTPOS, COMPUTERCLOUD, AWS, Docker
To live is to risk it all Otherwise you are just an inert chunk of randomly assembled molecules drifting wherever the Universe blows you

© 2024 jialin00.com

Original content since 2022

back
RSS

Behind the Scenes: Anycast and Its Impact on CDNs

When looking into content delivery solutions offered by major companies like Cloudflare, Amazon CloudFront, and Google Cloud CDN, you'll find they all provide similar content delivery network services and website security features. Let's dive into how these systems work and why they're important.

Why CDN is Important?

Because it serves content from the nearest server to the user.

For example, when you request a script that's replicated across multiple geographic locations, you'll receive it from the closest server, resulting in faster delivery times. This makes perfect sense, right?

How Does Content Delivery Work Behind the Scenes?

Anycast technology.

But first, we need to understand the default unicast.

The Default — Unicast

In the world of networking, most of our intuitions are based on Unicast - the standard way of routing where each device has a unique IP address. This is what we're used to:

  • One IP address corresponds to one device
  • If two devices have the same IP, it creates conflicts
  • It's like each house having a unique postal address

This Unicast mindset is why many find Anycast confusing at first - it seems to break these fundamental rules we've internalized.

Anycast — Breaking the Unicast Paradigm

Anycast allows multiple servers to use the same IP address.

Here's how it works:

  • Multiple servers (or data centers) in different geographical locations announce the same IP address
  • When a request is sent to this IP address, routers direct it to the "nearest" server
  • The "chosen one" is typically determined based on network topology rather than actual geographical distance

Anycast is made possible by BGP (Border Gateway Protocol) ⬇️

That’s why Anycast is needed when discussing CDNs.

When you type "1.1.1.1" (Cloudflare's DNS service) into your browser, your request might hit different physical servers depending on your location. But to you, it's all just "1.1.1.1" - simple and fast!

BGP and Anycast: A Perfect Partnership for Efficient Routing

Anycast is an implementation abstracted on top of BGP.

A real-world analogy

Imagine routers as people on the street, each with different levels of knowledge about the city. BGP is like their method of learning and deciding "how should I go" - considering not just geography, but also factors like traffic congestion.

Key points

  1. Announcement: Anycast nodes use BGP to tell these "street people" (routers): "Hey, we're all using the same address!"
  1. Learning Process
    1. Not every router needs to learn BGP. If you're a "person" who never leaves home (like a home router), you don't need to learn these complex routes
    1. BGP knowledge is not a mandatory skill for all routers
    featuresCore RoutersEdge RoutersAccess Routers
    need learn BGPyesyesno
    examplesRouters between ISPsEnterprise gateway routersHome routers, small office routers
    withInternal: IGP (OSPF, IS-IS), External: BGPInternal: OSPF, External: BGPDHCP is enough
  1. Decision Making: When traffic arrives, BGP-savvy routers can direct it to the "best" Anycast node based on:
    • traffic (like avoiding rush hour traffic)
    • Number of hops (like the number of turns in your route)
    • Various routing policies (some paths might be preferred over others)

A typical flow looks like this

User Request ➡️
Local ISP Router (Doesn't know BGP) ➡️
BGP-enabled Router (Knows the best path) ➡️
Chosen Anycast Node

Google Cloud Load Balancer vs Anycast

Google Cloud Platform's (GCP) load balancer uses a global IP address, which might seem similar to Anycast but isn't quite the same. Instead of being a true Anycast IP, it's a Virtual IP (VIP) managed by Google's global network infrastructure.

Here's how it works:

  1. Requests first reach the nearest Google edge location
  1. They're then routed within Google's private network to appropriate load balancers
  1. Load balancers distribute traffic to different regions based on factors like user location and backend health

Important Note: GCP's routing decisions aren't solely determined by Internet routing protocols. Think of it as having its own specialized BGP-like logic that goes beyond traditional BGP, enhancing load balancing and network optimization capabilities.

https://www.cloudflare.com/learning/cdn/glossary/anycast-network/

EOF