A zero-cost, split-brain immune active-passive failover system. Built for mission-critical e-commerce order fulfillment engines, single-leader background queues, and self-hosted automation engines (n8n/Python) without enterprise Kubernetes overhead.
Most web apps use active-active load balancing where multiple servers share incoming traffic. However, critical background automation workloads โ such as order fulfillment engines, transactional webhook consumers, and queue orchestrators (like n8n) โ operate under a strict Single-Leader constraint.
If two instances run concurrently on separate servers, catastrophic failures occur:
Enterprise solutions (Kubernetes multi-node clusters, managed Consul, or Cloudflare Load Balancers) require expensive infrastructure tiers ($50โ$250+/month) and high operational complexity. The objective was to engineer a lightweight, production-grade alternative that guarantees single-leader exclusivity with 100% free-tier cloud resources.
The failover architecture decouples ingress traffic routing from local service lifecycle management using three lightweight components:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Inbound Webhook Event โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ HTTPS POST
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Cloudflare Worker (Edge Router) โ
โ Key Cache: 5s at Edge โ
โโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโ
โ โ โ
โผ Read Lease Key โผ Route to Active โผ Route if Promoted
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ Upstash Redis Cloud โ โ Cloudflare Tunnel โ โ Cloudflare Tunnel โ
โ (Distributed Lease) โ โ Node A (Primary) โ โ Node B (Secondary) โ
โ failover:leader โ โโโโโโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโ
โ TTL: 120s (Auto) โ โ โ
โโโโโโโโโโโโโฌโโโโโโโโโโโ โผ โผ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
HTTPS REST Lease โ SERVER NODE A (VPS) โ โ SERVER NODE B (NAS) โ
Renew / Poll 10-60s โ โโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ [Failover Watchdog] โ โ [Failover Watchdog] โ
โโโโโโโโโโโโโโโบโ Status: LEADER โ โ Status: STANDBY โ
โ โ โ โ โ
โ โ [Order Engine Stack] โ โ [Order Engine Stack] โ
โ โ State: RUNNING [ON] โ โ State: STOPPED [OFF] โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ โฒ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Watchdog daemons run on each node, communicating with Upstash Redis through atomic REST leases.
If Node A loses internet connectivity or fails to renew its lease before TTL expiry, Node A
executes immediate local self-fencing (invoking
docker compose stop) before Node B is permitted to claim leadership. This
mathematical guarantee prevents two leaders from ever co-existing.
When Node A recovers after a power or network failure, it checks the distributed state before taking any action. Since Node B has successfully assumed leadership, Node A gracefully settles into Standby mode. This prevents destructive flip-flopping ("flapping") back and forth between servers.
Traditional DNS-based failovers take 5 to 30 minutes to propagate through internet ISPs. This engine uses a Cloudflare Worker as an edge reverse proxy. It inspects the active leader key from Redis cache and immediately proxies requests to the healthy server tunnel with zero DNS propagation lag while preserving exact request headers and signatures.
Real-Time Control Center Dashboard: Live leader monitoring, TTL countdown timer, and 1-click manual switchover interface.
Edge Routing Layer: Cloudflare Worker proxying inbound webhook traffic dynamically to healthy tunnel endpoints.
Distributed Atomic Lease State: Stored in serverless Redis cloud with millisecond precision and TTL auto-expiry.
Live Container Telemetry (docker stats): Demonstrating negligible resource footprint (< 0.1% CPU, ultra-lean RAM) while actively monitoring distributed Redis leases and node health.
While originally deployed to safeguard a mission-critical e-commerce order fulfillment engine, this architecture was engineered as a reusable, modular failover pattern. It seamlessly orchestrates:
| Metric | Traditional Cloud Clustering | RafiqFlow Failover Engine |
|---|---|---|
| Monthly Tooling Cost | $50 โ $250+ / month | $0 / month (100% Free Tiers) |
| Memory Footprint | 500MB โ 2GB (K8s/Consul agent) | < 100MB RAM Total |
| Split-Brain Immunity | Requires 3+ Quorum Nodes | Guaranteed via 2-Node Self-Fencing |
| Inbound Firewall Ports | Must open internal cluster ports | 0 Ports Opened (Outbound Tunnels) |
| Uptime SLA | 99.9% (Standard Multi-Node) | > 99.9% |
Let's discuss how to deploy a zero-cost, split-brain immune failover architecture for your critical background queues, webhooks, or automation engines.