how/network
1.1.1.1 answers fast from anywhere in the world because it physically lives in many places at once. The trick is BGP: each client lands on the nearest node.
When you ping 1.1.1.1 (Cloudflare DNS) from Moscow, the reply
comes back in 20ms. From Tokyo, also 20ms. From San Francisco,
also 20ms. Magic?
Not magic. Anycast. One IP address is announced from dozens of physical locations at once through [[bgp|BGP]]. Each client, by normal BGP logic, lands on the node nearest to it and sees low latency.
If a node goes down, BGP automatically stops announcing it, and traffic switches to the next nearest one. No application-level health checks, no config changes: failover in seconds.
Press ▶ to watch one 1.1.1.1 serve clients from 3 regions and see
how failover works.
Cloudflare has three data centers: New York,
Frankfurt, Singapore. Each one has a separate physical server,
ordinary "hardware". But all three listen on 1.1.1.1 and
announce this prefix through BGP to their regional ISP.
From BGP's point of view this is three independent announcements of the same prefix. Each ISP sees one of them (its own nearest).
recap
What to remember:
1.1.1.1, 8.8.8.8 are both anycast),
CDN edges, DDoS protection (the attack spreads across all nodes),
global API endpoints. All 13 root DNS servers are anycast,
physically there are hundreds of machinesRelated to bgp (announcements and path selection) and [[dns-resolution|DNS]] (where anycast is used most often).