Engineering case study
ATLAS job scheduler
ATLAS runs short compute jobs on a Kubernetes worker pool. Job state lives in PostgreSQL, so a restarted scheduler can resume from the queue and a lost worker can be replaced without discarding its unfinished jobs.
Run the live labWatch recoveryDownload source
How the runtime works
SharedDefault · all visitors
PersonalOpt-in private runs
- Replicas per pool
- 2–10
- Concurrent jobs per pod
- 4
- Worker lease
- 5 s
Scaling, recovery, and telemetry
Scheduling and autoscaling
Workers request jobs over HTTP. The Go scheduler claims eligible PostgreSQL rows on their behalf with FOR UPDATE SKIP LOCKED. KEDA targets 25 queued jobs per pod. Kubernetes uses a 60-second scale-down stabilization window.
Failure recovery
Heartbeats renew leases. An expired lease returns the job to the queue and the next claim advances its attempt epoch. PostgreSQL rejects stale completions and accepts one successful result per job.
Observability
WebSockets stream progress to the browser. OpenTelemetry sends spans to Tempo and pod logs to Loki. Prometheus tracks queue depth, worker capacity, and API latency.
Local deployment uses one K3s node and one PostgreSQL instance.
Why PostgreSQL for the queue?
A claim transaction picks eligible jobs with FOR UPDATE SKIP LOCKED, updates their ownership, and records attempts together. Completion writes the result and closes its attempt under the same job-row lock. The queue and its audit trail share one transaction boundary.
Kafka would bring partitioned log replay and consumer groups. The application would still need a durable result store and a way to coordinate result writes with message offsets. Redis Streams could handle delivery and pending-entry reclamation, with separate decisions about persistence and atomically recording results. PostgreSQL keeps this deployment small. Frequent heartbeats and updates can add row contention, WAL traffic, and vacuum work as load grows.
Why leases and attempt epochs?
A worker owns a claim for five seconds and renews it with heartbeats while the attempt is active. If the worker exits or its renewal arrives too late, the scheduler expires the attempt and requeues the job. Each claim increments a per-job epoch. Completion checks the worker ID, epoch, job state, and lease under a row lock. A request from a stale attempt cannot overwrite a result.
- Queued
- Running · attempt 1
- Lease expired
- Queued again
- Running · attempt 2
- Result committed
Execution can repeat. The completion path can acknowledge a retry of a successful result for the same worker and epoch. The scheduler stops retrying after three attempts. Job handlers that write to an external service would need their own idempotency guarantees.
Why scale on queue depth?
A burst creates visible demand before the running pods finish enough work to keep up. KEDA reads the backlog per pool and publishes the metric to the Kubernetes HPA, targeting 25 queued jobs per pod across a range of 2–10 pods. Each worker has four execution slots. A 60-second scale-down window helps absorb short gaps in arrivals. A queue-length target treats jobs as roughly equal in cost, so batches mixing workloads can show different p95 queue times.
What can fail, and what is measured?
The deployment uses one K3s node and one PostgreSQL instance. Results demonstrate process and worker recovery on that node. A host or database outage interrupts service for the cluster, and throughput is bounded by shared CPU, database capacity, and the scheduler’s request path.
Benchmark reports state the workload, worker count, build, host, and job accounting. Traces show claims and completions per attempt, audit events record lease expiration, and Prometheus tracks runtime queue depth and API latency.
- Throughput
- 129.1 jobs/s
- First job reclaimed
- 5.36 s
- Hash jobs completed
- 10,000 / 10,000
- Duplicate commits
- 0