Anycast advertises one IP from multiple PoPs (Points of Presence). BGP picks the route with the shortest AS-path; user traffic lands at the topologically closest PoP.
If a PoP goes down, BGP withdraws its route; users automatically failover to the next-closest PoP. This is how Cloudflare, 1.1.1.1, and most modern CDNs handle resilience without complex DNS games.