Deleting Our Custom Scale-to-Zero Gateway: 16.3s to 2.4s Cold Wake and -80% RAM with KEDA
Why our homemade Node.js and Python idle gateway grew past 4,500 lines and 855 MiB of resident RAM—and how replacing it with KEDA + KEDA HTTP Add-on cut cold wake latency ~6.9x.
Every homelab-turned-PaaS builder eventually hits the same temptation: "How hard can scale-to-zero HTTP routing really be? I will just write a lightweight proxy that buffers requests for 10 seconds and bumps Deployment replicas from 0 to 1."
We fell straight into that trap. Over a few months of rapid iteration, our "simple" idle proxy ballooned into 3,623 lines of Python across seven modules (http_idle.py alone reached 1,937 lines) plus 971 lines of custom Node.js gateway code (gateway.mjs / fleet.mjs), 6 always-on Gateway Pods, 4 credential-renewal CronJobs, and 29 per-namespace NetworkPolicy objects.
By late November, ripping all of it out in favor of upstream KEDA (2.21.1) + KEDA HTTP Add-on (0.16.0) became one of the highest-leverage engineering wins on our Kyoto cluster.
What Broke With Our Custom Idle Gateway
In isolation, a custom proxy feels easy to control. In production across dozens of sleeping apps, the glue cost compounded fast:
- Painful cold wake latency (
16.35s): Between control-plane reconciliation polling, multi-hop proxying (6–7 hops even for awake apps before we bolted on a metric-driven bypass), and hold/re-engage grace windows, waking an app from0Pods took16.35sin end-to-end verification. - High idle footprint (
855–857 MiBRAM): Keeping 6 custom Node.js gateway Pods warm (to cover our shared idle pool and edge routing) burned855–857 MiBof RAM and20–21mCPU just waiting for traffic. - Self-inflicted DB locks & CronJob churn: The idle reconciler hammered the Control Plane database with 5-second heartbeat loops. During our PostgreSQL migration, reverse lock ordering between state persistence and heartbeats even triggered
40P01 DeadlockDetectederrors. - Complex state machines to avoid deletion deadlocks: Because our gateway held synthetic Ingress state and per-namespace network policies, deleting an active app required carefully timed grace windows (
AWAKE_BYPASS_GRACE_SECONDS=15,REENGAGE_GRACE_SECONDS=10) to avoid503s orSTOP_APP_FIRSTdeadlocks.
Why We Picked KEDA HTTP Add-on (and Rejected Sablier)
Before migrating, we evaluated Traefik Sablier (v1.21.1) as a potentially even simpler alternative. We ruled it out for three concrete reasons:
- Its Kubernetes
blockingstrategy had a known synchronization race causing infinite redirect loops under load (sablier#1273). - Its
dynamicstrategy returns an HTML waiting page—which breakscurl, mobile APIs, and webhook callers expecting JSON. - It required experimental Yaegi plugin injection directly inside our production Traefik Pods.
KEDA + KEDA HTTP Add-on, on the other hand, ran cleanly in its own isolated keda namespace, kept production Traefik completely untouched, and let the Go-based KEDA HTTP Interceptor hold incoming connections (both browsers and JSON/API callers) until the target Pod passed readiness probes—returning a direct, transparent HTTP/2 200 with zero redirects and zero HTML waiting screens.
Before vs. After: Real Kyoto Cluster Numbers
Moving all apps from our custom idle stack to InterceptorRoute + HTTPScaledObject + ScaledObject delivered immediate, measurable wins across both single-app tests and full production rollout:
| Metric | Custom http_idle Gateway | KEDA 2.21.1 + HTTP Add-on 0.16.0 | Delta |
|---|---|---|---|
Cold wake latency (0 -> 1 Pod, gVisor) | 16.35s | 2.383s (PoC) / 3.64–3.90s (prod E2E) | ~4.2x–6.9x faster |
5-way concurrent cold burst (0 -> 1) | — | 5/5 HTTP/2 200 in 3.42s | Zero 503s |
| Steady-state proxy latency overhead | 6–7 hops (pre-bypass) | +1.7ms p50 (89.1ms -> 90.8ms) | Near wire speed |
| Idle infrastructure Pods & RAM (PoC parity) | 6 Pods / 855–857 MiB | 8 Pods / 153–174 MiB (246 MiB post-rollout) | ~80–82% less RAM (PoC) |
| Custom code & K8s policy sprawl | 4,594 lines + 29 NPs | Net -11,500 lines deleted across final wave | Massive diet |
Stateful apps backed by persistent volumes also resumed cleanly (12.661s cold wake including ReadWriteOnce volume reattachment with data intact), and both SSE chunked streaming and WebSockets (wss:// 101 Switching Protocols) worked transparently through the KEDA Interceptor.
Two Subtle Details That Saved Us in Production
Adopting upstream KEDA did not mean zero glue—two small patterns kept production rock-solid:
- Stopping an app explicitly without breaking scale-to-zero: When a user intentionally stops an app (
pangea stop), random internet scanners hitting its URL must not silently wake it back up. Setting KEDA's standardautoscaling.keda.sh/paused-replicas: "0"annotation on theScaledObjectalongside a retired Ingress state kept explicitly stopped apps pinned at0Pods (5/5 HTTP 404), even under direct edge requests. - Keeping
kedatight with Cilium + CEL: We kept KEDA'snamespacelocked down with 6 minimalCiliumNetworkPolicyrules (remembering to allowfromEntities: [host]on port8081so kubelet probes tokeda-http-operatorstay green), while letting KubernetesValidatingAdmissionPolicyvalidate route definitions declaratively.
Takeaway
The biggest lesson from retiring our custom idle gateway aligns with a rule we now enforce across the platform: solve 80%+ of infrastructure mechanics with boring, upstream CNCF tooling, and keep your custom code focused purely on the thin product boundary. Deleting >11,000 lines of custom code made cold wakes ~6.9x faster—and made my evenings dramatically quieter.