Zero-Downtime Edge Failover & Alert Deduplication
When origin servers crash, traditional CDNs serve raw 502 Bad Gateway errors while flooding on-call inboxes with thousands of duplicate alerts. Here is how we engineered an intelligent, open-source edge sentinel worker on Cloudflare to guarantee zero-downtime resilience.
Key Architectural Takeaways
1. The Anatomy of an Origin Failure
When a database locks, an out-of-memory crash occurs, or a rolling deployment goes wrong, every single incoming user request triggers an error. If you have 500 requests per second, a naive monitoring script will attempt to send 30,000 alert emails in a single minute.
2. 3-Tier Multi-Colo Deduplication Architecture
Cloudflare Workers run on hundreds of edge datacenters worldwide. To achieve robust alert deduplication without incurring high KV write costs or latency bottlenecks, we designed a 3-tier locking hierarchy:
Isolate Memory
0ms check. Prevents in-flight race conditions across concurrent requests within the active worker isolate.
Cache API (caches.default)
~1ms check. Edge datacenter per-colo lock. Prevents alert duplication across requests hitting the same city edge.
Global Cloudflare KV
Cross-datacenter lock. Deduplicates alerts worldwide across 300+ global edge locations.
3. Quickstart & Implementation
Deploying cloudflare-edge-failover takes under 2 minutes:
# 1. Clone the open-source repository
git clone https://github.com/Epheos-LTD/cloudflare-edge-failover.git
cd cloudflare-edge-failover
# 2. Install dependencies & configure
npm install
cp wrangler.toml.example wrangler.toml
# 3. Deploy to Cloudflare Workers
npm run deploySupported Alert Integrations
Out-of-the-box support for Cloudflare Worker Email, SendGrid, MailChannels, Discord incoming webhooks, and Slack alerts.
Open Source on GitHub
This project is maintained by Epheos LTD under the Apache 2.0 license. Star the repo, fork it, or submit your contributions!
View cloudflare-edge-failover on GitHub