Portfolio

The core finding

0.0 s Wasted compute
predictive (Argus)
4.3 s Periodic
checkpointing
169.4 s Reactive on the
2-min notice ⚠

When interruptions arrive faster than the two-minute warning window, reacting to the notice stops helping. Across 80 trials at MTBF = 120 s, prediction wasted zero compute and recovered 12× faster than periodic checkpointing.

scroll to expand

Kubernetes kopf SpotResilientJob CRD AWS EKS Terraform IRSA / OIDC S3 · SQS · Lambda Prometheus Grafana PyTorch
GitHub
10 s Node drained on a real EKS Spot interruption
~75 s Until training resumed on a healthy node
5.4 s Mean recovery, predictive arm — 12× faster
14.68× Base-rate lift of the risk model (5-seed mean)
The core finding

Reacting to the two-minute notice is already too late

EC2 Spot gives you a two-minute warning. The standard answer is to catch it and checkpoint. Over 80 trials at MTBF = 120 s, that reactive arm still burned 169.4 s of wasted compute — barely better than no protection at all (202.3 s) — because interruptions arrived faster than the notice window could absorb. Predicting the interruption instead brought wasted compute to 0.0 s and mean recovery to 5.4 s, against 65.7 s for periodic checkpointing.

Spot instances are 70–90% cheaper than on-demand, which makes them the obvious home for long training runs — right up until a reclaim throws away an afternoon of gradient steps. Argus treats that as a scheduling problem rather than a retry problem: a risk model watches the market, a Kubernetes operator acts on the risk score before the notice arrives, and the training job itself only ever has to answer one question — "should I flush a checkpoint right now?"

Architecture

Three layers, decoupled by S3

LAYER 1 — PREDICTION LAMBDA COLLECTOR EC2 Spot price history EventBridge · every 5 min S3 FEATURE STORE eu-north-1 history TRANSFORMER RISK MODEL SpotInterruptionPredictor risk ∈ [0, 1] · 14.68× lift FastAPI /predict instance_type · az → risk_score LAYER 2 — ORCHESTRATION kopf OPERATOR · SpotResilientJob CRD @kopf.timer polls /predict every 60 s — risk > threshold triggers migration _FLUSH_TRIGGER → S3 decoupled from trainer internals SQS RISK EVENT checkpoint_and_migrate CORDON NODE unschedulable = true RESCHEDULE POD instanceFallback list LAYER 3 — TRAINING PyTorch CIFAR-10 JOB polls trigger every 100 batches flushes model.pt → S3 then deletes the marker REACTIVE PATH — SIGTERM AWS Node Termination Handler 2-min warning via SQS flush before the pod dies REPLACEMENT POD resumes from the saved epoch ~75 s after the drain one epoch of work replayed OBSERVABILITY argus_risk_score · argus_checkpoints_total · argus_jobs_completed_total → Prometheus → Grafana
Core implementation

The operator never touches the training loop

The reconcile loop is a kopf timer on a custom resource. Every 60 seconds it polls the prediction service for the job's instance type and AZ, records the score on the CR status and on a Prometheus gauge, and does nothing at all while risk stays under the threshold.

When risk crosses it, the operator does not reach into the trainer. It writes a _FLUSH_TRIGGER marker to S3 — the training pod polls that key every 100 batches, writes model.pt, and deletes the marker. The contract is a single object in a bucket, so the operator and the training process share no code and can be replaced independently.

Only then does it cordon the node and reschedule the pod onto the next instance type in the CR's instanceFallback list, publishing an SQS event on the way out. Phase transitions (Running → Checkpointing → Migrating) are guarded so a second reconcile can't double-migrate a job already in flight.

The whole AWS footprint — VPC, EKS control plane and Spot node groups, S3, SQS, ECR, Lambda and the IAM roles — is Terraform. Pods reach AWS through IRSA/OIDC, so there are no static credentials anywhere in the cluster.

python operator/controller/handlers.py
@kopf.timer("argus.io", "v1", "spotresilientjobs",
            interval=POLL_INTERVAL)
def reconcile(spec, name, namespace, status, patch, **kw):
    # Already migrating? leave it alone.
    if status.get("phase") in ("Checkpointing",
                              "Migrating",
                              "Succeeded"):
        return

    # 1. Poll the prediction service
    risk_score = httpx.get(
        f"{PREDICT_SERVICE_URL}/predict",
        params={"instance_type": instance_type,
                "az": "eu-north-1a"},
    ).json()["risk_score"]

    risk_score_gauge.labels(job_name=name).set(risk_score)
    if risk_score <= risk_threshold:
        return

    # 2. Checkpoint via S3 marker — no trainer coupling
    patch.status["phase"] = "Checkpointing"
    trigger_s3_checkpoint(name, checkpoint_path)
    checkpoint_count.labels(job_name=name).inc()

    # 3. Cordon the doomed node, reschedule the pod
    patch.status["phase"] = "Migrating"
    scheduler.cordon_node(scheduler.get_pod_node(name, namespace))
    scheduler.reschedule_pod(name, namespace, fallback_types)
Results

Four arms, 80 trials, one real interruption

Wasted compute per arm at MTBF = 120 s — bars share one scale (0–202.3 s). Lower is better; the predictive arm's bar is empty because it wasted nothing.

No protection
202.3 s
Reactive (2-min)
169.4 s ⚠
Periodic checkpoint
4.3 s
Predictive (Argus)
0.0 s
ArmWasted computeRecovery
No protection202.3 s—
Reactive169.4 s58.8 s
Periodic4.3 s65.7 s
Predictive0.0 s5.4 s

The end-to-end drill on a live EKS cluster — training was at epoch 7 on a Spot node when the interruption landed.

Time (UTC)Event
12:26:18NTH receives the interruption warning
12:26:19SIGTERM handler writes epoch-8 checkpoint to S3
12:26:25Node cordoned and drained — 10 s end to end
+ ~75 sReplacement pod resumes from epoch 8

Stated limitation: the interruption was a schema-conformant message injected into the Node Termination Handler's queue, not an AWS FIS-issued reclaim. Everything downstream of that message — drain, checkpoint, cordon, reschedule, resume — ran on real EKS against real S3.

The risk model is likewise advisory-grade: 14.68× base-rate lift (5-seed mean, 95% CI ≈ [9.9×, 19.5×]) on live eu-north-1 price history, trained against a price-spike proxy rather than reclaim ground truth.

A $66 EKS cluster left running overnight paid for the last piece: every session now ends with an all-region teardown sweep, which kept the whole project inside its $100 credit.

Terraform · operator · benchmark harness

Reproduce the interruption drill