← All posts

Network

How we take a sick location out of service in under a second

Anycast makes failover a routing decision. The hard part is deciding when a location is unhealthy, and not flapping. Inside our health quorum, BGP withdrawals and hold-down timers.

Network Engineering4 min read

Every Cache.bz location announces the same IP prefixes over BGP. Visitors are routed to whichever location is closest in network terms, and if a location stops announcing, the internet routes its visitors to the next closest one. That is the theory behind anycast failover, and it is why we can promise that a failed location is out of service in under a second. The theory is simple. Deciding when to pull the trigger is not.

Why not just use the routers?

BGP itself only notices failures it can see: a link going down or a session timing out. Most real failures look nothing like that. A cache process can be wedged while the server, the switch and the BGP session are perfectly healthy. A storage controller can start returning errors on half the disks. A location can lose its path to the shield tier while still reaching visitors. In all of these cases, the routers would happily keep sending traffic to a location that cannot serve it properly.

Health from the inside

Each location runs a small daemon, edge-health, on every cache node. It checks the things that actually matter for serving a request: that the local cache process answers a synthetic request end to end, that a known object can be read from NVMe, and that the shield tier and a reference origin are reachable. Each check runs every 100 to 500 milliseconds with a timeout shorter than the interval.

checks.toml
# /etc/edge-health/checks.toml (excerpt)
[[check]]
name     = "cache-local"
target   = "http://127.0.0.1:8081/__health/cache"
interval = "100ms"
timeout  = "250ms"
fail_after = 3          # 3 misses in a row = unhealthy

[[check]]
name     = "shield-reach"
target   = "tcp://shield.fra.internal:443"
interval = "500ms"
fail_after = 4

[withdraw]
quorum        = 0.5     # withdraw when half the cache nodes are unhealthy
hold_down     = "30s"   # never re-announce sooner than this
max_flaps_hr  = 4

A single node failing is not a reason to withdraw a location; the local load balancer removes it from rotation and the others absorb its share. The location as a whole withdraws its anycast prefixes only when a quorum of nodes is unhealthy, by default half of them. That rule exists because the failures that matter most, a bad configuration push or a broken shared dependency, affect every node at once.

Withdrawing quickly

When quorum is lost, edge-health tells the local BGP daemon to withdraw the anycast prefixes on every session: transit, peering and route servers. Withdrawals propagate fast, usually within a few hundred milliseconds to the networks that matter, because they are small and most networks process them immediately.

Failover timeline 0 msfirst probe fails 300 msquorum lost 310 msBGP withdraw sent ~650 mstraffic on neighbours
A typical withdrawal from first failed probe to traffic arriving at neighbouring locations.

Here is a real example from a test in our Amsterdam location in February, where we deliberately wedged the cache process on nine of sixteen nodes:

edge-health log
14:31:07.112 edge-health[2214] cache-local FAIL 3/3 node=ams-c07 (timeout 250ms)
14:31:07.118 edge-health[2214] cache-local FAIL 3/3 node=ams-c11 (timeout 250ms)
14:31:07.403 edge-health[2214] quorum lost: 9/16 nodes unhealthy -> WITHDRAW
14:31:07.409 bird[1180]  anycast4: withdrawing 3 prefixes on 6 sessions
14:31:07.744 edge-health[2214] neighbour FRA confirms traffic shift (+18.2 Gbps)

From the first failed probe to Frankfurt seeing the extra traffic took 632 milliseconds. Visitors with connections in flight saw them reset, and browsers retried on a new connection that landed in Frankfurt. HTTP/3 clients migrated even faster.

Not flapping

The dangerous failure mode of any automatic failover is flapping: a location that withdraws, recovers, re-announces, gets flooded with returning traffic, fails again, and repeats. Each cycle resets connections for every visitor in the region. We guard against it in three ways.

  • Hold-down. A location that withdrew does not re-announce for at least 30 seconds, and only after every check has passed continuously for that whole period.
  • Gradual return. Re-announcement starts with prepended paths, which makes the location less attractive, and removes the prepends over two minutes so traffic returns in steps.
  • Flap limit. After four withdrawals in an hour, the location stays out until an engineer reviews it. This has triggered twice in the past year, both times correctly.

Testing it every week

Failover that is never exercised does not work when you need it. Every week we withdraw one location on purpose during its lowest-traffic hour and verify that neighbours absorb the load, that latency for affected visitors stays within budget, and that the location returns cleanly. The test schedule rotates through every city. Those weekly withdrawals are scheduled and announced as maintenance on our status site, so if you have ever seen a short note about one of them, now you know why.

Anycast is not magic, and it is not a replacement for good capacity planning. But combined with honest health checks and a strong bias against flapping, it lets a location fail without visitors noticing much more than a single retried request. The shield tier follows the same health model, which we will cover in a future post.

Questions or corrections? Write to the engineering team at hello@cache.bz. We read everything and update posts when we get something wrong.