Skip to content
ZERONE
Nazad na Insights
Distribuirani sistemi2026-07-06 · 8 min čitanja

Four layers of cost protection: how our auto-scaler doesn't explode the bill

A client uploads a broken scene, the orchestrator spawns a pod, the pod runs into infinite OOM, tries three retries, each pod costs us $0.80/minute. Without protection this becomes a three-digit bill in an hour. Four independent layers have to fail before we see that.

The most expensive mistake in a cloud rendering setup isn't the slow render — it's the render that runs forever. A GPU pod at US$0.80/minute is $48 in an hour, $576 in 12 hours, $2,300 over a weekend. If the software can crash and the orchestrator "just restarts it", that's not auto-recovery — that's a bill that stops clients from coming back.

Our cinema-orch backend has four independent cost-protection layers. Since sprint 3.5 (2026-06-15) all four are live. Each layer fails differently from the others — so at least two have to fail before we see an overshoot.

Layer 1: Ex-ante estimate + client confirm

Before any pod spawns, the orchestrator computes a cost estimate from sample count × tile count × frame count × estimated time/frame on the chosen GPU, plus a baseline from historical jobs of the same scene signature, plus a 20 % buffer. The estimate is shown to the client before start. The client must actively confirm. If the estimate is above the client's budget (each user sets a hard cap), the job is rejected — not queued, not confirmed-with-warning, but rejected outright.

Effect: about 70 % of theoretically expensive jobs never enter the orchestrator, because the client optimises the scene first.

Layer 2: Per-job budget cap with live ticker

Each job has a max_budget_cents field. The orchestrator runs a ticker in Postgres — once a minute the accumulated cost is checked against max_budget_cents. If the job hits the cap, the pod is hard-terminated. The user gets a notification and can raise the cap or take the partial output.

Effect: a runaway render can overshoot by ~5–10 % max (until the next ticker tick fires). On a $50 job that's $2.50 overshoot, not $2,300.

Layer 3: Pod timeout at systemd level

Each GPU pod has a hard time limit set at pod init — analogous to a Kubernetes ActiveDeadline. Standard render session: 4 hours. On expiry, the pod dies and the orchestrator marks the job as budget_exceeded. This is the fallback for orchestrator crashes — the pod terminates itself without any external trigger.

Layer 4: Provider-side spending alert

Runpod (our primary GPU provider) has its own budget alerts. At $50/day spend, an email; at $200/day, a Slack alert. If the other three layers all fail, this catches us manually. In 4 weeks of beta it has never fired, because layers 1–3 catch everything.

Why four

One layer is no protection — it's a single point of failure. Four independent layers means one bug in some software (our UI, our orchestrator, systemd, Runpod's portal) doesn't cause an unexpected bill — the other three catch it.

The trick is independence. Layer 1 lives in the frontend (Next.js). Layer 2 in the orchestrator (Python/asyncpg). Layer 3 on the pod (systemd). Layer 4 at the provider (Runpod's API). If one software crashes, unlikely the other three fail the same way at the same time.

What we learned

Estimate accuracy is the biggest lever for layer 1. If the estimate is 30 % off, the cap buffer is gone before the job is done. Ticker interval in layer 2 is a trade-off between overshoot and DB load — 60 seconds is our compromise. Pod timeout in layer 3 must not be too short; we had 60 minutes early on, killed a legitimate 4K job at 90 minutes.

If you're building an auto-scaling system with external GPU-billing risk: don't start with a single cap. Build three independent ones plus a provider alert. Extra effort is small, risk delta is enormous.

We document this architecture openly because cloud rendering has to be honest about its own risks. If you'd like ZER0ONE Studio to look at the pattern for your own system, drop us a line — this kind of distributed-systems review is one of our engineering services.

Sličan požar?

Verovatno smo već videli nešto slično. Javite se.

Započni razgovor