FullStack AI Hub
Studio
Networking & Security · 01. Transport & Internet Routing
11 min
6 steps
Intermediate

BGP, Anycast & NAT Traversal

See how Autonomous Systems exchange BGP routes, how Anycast pulls users to the nearest PoP, and how STUN/TURN bridge strict NATs.

Networking & Security01. Transport & Internet RoutingLesson 2 of 2
11 minIntermediate6 steps

BGP, Anycast & NAT Traversal

See how Autonomous Systems exchange BGP routes, how Anycast pulls users to the nearest PoP, and how STUN/TURN bridge strict NATs.

AS Hops
2 ASNs
Active Route
Direct IXP
Edge RTT
14 ms
Announced
/24 Block
Pref 200Free peerFailoverTransitUser ISP (AS7018)IXP Direct PeerTier-1 TransitCloud EdgeASDirect IXP peering saves transit cost & shaves RTT
BGP / Anycast Packet
Direct P2P UDP Media
RPKI Validated / STUN
TURN Relayed Media
BGP Leak / SNAT Full
In This LessonStep 1 of 6
What You Will Master
  • ✓Understand how BGP chooses inter-domain routes using Local Preference and AS-Path length
  • ✓Use Anycast for nearest-PoP failover and RPKI Route Origin Validation to stop BGP hijacks
  • ✓Prevent cloud NAT gateway SNAT port exhaustion under high-churn egress traffic
  • ✓Combine STUN hole punching with global TURN TLS-443 relays for 99.9% WebRTC call setup

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
BGP Peering (IXP)Cutting transit costs and shaving latency between major ASNsSlow global convergence (30–90s) and route-leak risks without RPKI
Anycast IP PrefixGlobal DNS, CDNs, edge APIs, and distributed DDoS absorptionMid-flow BGP flaps can reset stateful TCP connections
STUN Hole PunchingZero-relay-cost direct peer-to-peer WebRTC media behind Cone NATsFails behind symmetric corporate NATs and UDP-blocking firewalls
TURN Media RelayGuaranteed call connectivity through strict enterprise firewallsEgress bandwidth scales linearly with relayed call minutes

Step-by-Step Architectural Breakdown (6 Steps)

Full architectural walkthrough transcript and state transitions for BGP, Anycast & NAT Traversal.

STEP 01 · SETUPJump to step →

Autonomous Systems & BGP Peering Policy

The internet is a mesh of Autonomous Systems (ASNs) exchanging IP prefix reachability via BGP. Border routers prefer free direct **IXP peering** (`LocalPref 200`) over paid Tier-1 transit even when multiple paths exist.

idea:BGP optimizes for business policy (Local Preference) first, and AS-Path hop count second.

ASNBGPLocal PreferenceIXP Peering
STEP 02 · SOLUTIONJump to step →

Anycast: One IP, Nearest Healthy PoP

With **Anycast**, Frankfurt and Virginia announce the exact same `/24` IP prefix simultaneously. Each user’s ISP routes packets automatically to the topologically closest PoP—and if Frankfurt withdraws its BGP route, traffic shifts to Virginia without waiting on DNS TTLs.

good:Anycast turns BGP itself into a zero-TTL global load balancer and failover fabric.

AnycastBGP WithdrawalNearest PoPGlobal Failover
STEP 03 · TECHNIQUEJump to step →

Preventing BGP Route Leaks With RPKI

Classic BGP trusts peer announcements blindly—so one typo announcing someone else’s `/24` can blackhole global traffic. **RPKI Route Origin Validation (ROV)** checks cryptographically signed ROAs and drops unauthorized prefix announcements at border routers.

watch:Publish RPKI ROAs for every prefix you own and enforce ROV-invalid drop at all peering edges.

BGP HijackRPKIROARoute Origin Validation
STEP 04 · PROBLEMJump to step →

NAT Conntrack Tables & SNAT Port Exhaustion

A VPC NAT Gateway rewrites private pod IPs (`10.0.1.x`) onto one public IPv4 with ~64,000 ephemeral ports per destination. High-churn microservices without HTTP keep-alive rapidly exhaust all SNAT ports, silently timing out new outbound connections.

watch:Attach multiple public IPv4s to busy NAT Gateways and reuse outbound HTTP keep-alive connections.

SNATConntrack TableEphemeral PortsTIME_WAIT
STEP 05 · SOLUTIONJump to step →

STUN & Direct P2P UDP Hole Punching

For WebRTC calls, both browsers first query a tiny **STUN** server to discover their public NAT-mapped IP:port, swap ICE candidates via signaling, and send simultaneous outbound UDP packets to punch pinholes through both home firewalls for direct zero-cost media.

good:STUN steps out of the media path after discovery—~85% of calls flow peer-to-peer at $0 relay cost.

STUNICE CandidatesUDP Hole PunchingCone NAT
STEP 06 · RECAPJump to step →

ICE Fallback to Global TURN TLS-443 Relays

For the ~15% of calls behind symmetric corporate NATs or UDP-blocking firewalls, ICE automatically selects a regional **TURN relay** listening on TLS port 443. Media stays end-to-end encrypted (DTLS-SRTP) while guaranteeing 99.9% call completion.

good:Always deploy regional TURN clusters with TLS 443 fallback so enterprise users never hit silent call drops.

TURN RelayICE FallbackTLS 443 TraversalDTLS-SRTP

Related Production Deep-Dives & Simulators

Related Systems Course
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.