Skip to content
Spacefolder Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Scale Temporal workers on Kubernetes

See when Temporal workers can release spare pods and when they need more capacity to start queued activities on time.

Availability score at 0, 10, 100, and 1,000 prior telemetry days. Spacefolder rises from 68 to 90 out of 100.

After 1,000 navigations per World

For infrastructure, the history checkpoints count prior days of queue and worker telemetry. After 1,000 days, Spacefolder scored 90.36 on 16 held-out workload days.

Approach Activities started on time Availability score / 100
Spacefolder 99.04% 90.36
Prometheus + scheduled review 97.91% 79.07
Tuned multi-metric HPA 96.82% 68.17
CPU-only HPA 85.47% 0.00
Ground truth 100.00% 100.00

A score of 0 means 90% or fewer activities started within two minutes. A score of 100 means every activity met that deadline. See the benchmark index for earlier checkpoints.

About our approaches

  • Spacefolder. The team sets the deadline and replica limits. The policy uses queue and worker telemetry to decide when to add or release pods. SDK example
  • Prometheus + scheduled review. A horizontal pod autoscaler (HPA) scales workers between reviews. The benchmark assumes engineers review throughput every four hours and take 30 minutes to approve and roll out a change. KEDA Prometheus trigger · Argo CD automated sync
  • Tuned multi-metric HPA. Engineers expose backlog and worker-slot metrics alongside CPU usage and tune the scaling targets. Temporal worker scaling · KEDA scaling ownership
  • CPU-only HPA. Engineers set CPU requests, a utilization target, and replica limits. Kubernetes adjusts the pod count. Kubernetes HPA
  • Ground truth. Perfect activity-start availability scores 100 at every checkpoint.

TypeScript SDK example

Record one observation per queue per minute, then compare holding and releasing warm pods over the startup window. The worker controller supplies the telemetry and candidate floors. TypeScript SDK · Fold API · Navigate API

import { SpacefolderClient } from "@spacefolder/sdk";

const sf = new SpacefolderClient();

async function compareReserve(
  queue: string, minuteEnd: string, holdFloor: number, releaseFloor: number,
  sample: {
    arrivals: number; starts: number; backlog: number; lateStarts: number;
    readyPods: number; slotUtilization: number; downstreamThrottled: boolean;
    requestedPodMinutes: number;
  },
) {
  const scope = { world_id: "worker_scaling", entity_type: "task_queue", entity_id: queue };
  const event = "temporal.worker_minute";
  await sf.fold({
    world_id: scope.world_id,
    events: [{
      entity_type: scope.entity_type, entity_id: queue, timestamp: minuteEnd,
      id: `${queue}:${minuteEnd}`, name: event, data: sample,
    }],
  });
  const navigation = await sf.navigate({
    ...scope, nav_id: "temporal.worker_reserve", context: sample,
    actions: {
      hold: { name: "worker.reserve", data: { floor: holdFloor } },
      release: { name: "worker.reserve", data: { floor: releaseFloor } },
    },
    predictions: {
      late: { type: "metric", event, field: "data.lateStarts", aggregation: "sum", horizon: "5m" },
      cost: { type: "metric", event, field: "data.requestedPodMinutes", aggregation: "sum", horizon: "5m" },
    },
  });

  for (const action of ["hold", "release"] as const) {
    const forecast = navigation.actions?.[action]?.predictions;
    const late = forecast?.late;
    const cost = forecast?.cost;
    console.log({
      action,
      lateStarts: late && "value" in late ? late.value : null,
      podMinutes: cost && "value" in cost ? cost.value : null,
    });
  }
}

Example output

For example, if both reserves forecast zero late starts over the next five minutes, the controller can release pods to use fewer pod-minutes.

{ action: 'hold', lateStarts: 0, podMinutes: 90 }
{ action: 'release', lateStarts: 0, podMinutes: 70 }

The controller keeps the current reserve when evidence is insufficient. It records the floor it applied, subsequent waits, and pod usage.

In depth

Cost and reliability at 8× load

Across two separate sets of 1,024 workload days, every activity started within two minutes. On the second set, Spacefolder used 466,634 fewer worker pod-hours (11.65%) than Prometheus + scheduled review. Scheduled review missed 21,805 activity-start deadlines on the same traffic.

The table compares policies on the second set of 1,024 days. Five nines allows one late start per 100,000 activities each day. All policies faced the same generated traffic, worker slowdowns, and three-minute pod startup time.

Scaling policy Pod-hours saved vs. scheduled review Late starts Days below five nines
Spacefolder with slowdown warning 11.65% 0 0
Spacefolder without the warning 12.34% 2,893 2
Prometheus + scheduled review — 21,805 4

When a burst hits

In one earlier workload, arrivals jumped from 464 to 3,760 per minute as throughput fell from 48 to 18 starts per pod. Spacefolder requested extra pods at minute +1, as soon as it could read the burst minute’s telemetry.

Ready pods and activities waiting during a burst. At the minute +4 deadline, Spacefolder had 224 pods ready with the warning and 173 without it. The warning cleared the queue for the affected group.

At the start of minute +4, 3,384 activities from minute +2 still needed to start. Without the warning, 173 pods could start 3,114 that minute, leaving 270 late. With the warning, 224 pods could start 4,032, enough for every activity in that group to meet its two-minute deadline.

When traffic is quiet

On a separate 512-day base-load test, Spacefolder learned when it could release four of its 18 warm pods. That decision alone saved 8,672 pod-hours versus keeping the same 18-pod minimum. Overall it used 13.1% fewer pod-hours than scheduled review, and all 68.7 million activities started on time under both policies.

Pod-hours by availability target

Worker pod-hours and downstream throughput needed to meet 99.9%, 99.99%, and 99.999% activity-start availability.

On this base-load comparison of 16 days, Spacefolder used the fewest pod-hours at 99.9% and 99.99%. Scheduled review used the fewest at 99.999%. Even with all 24 pods ready, five nines required downstream capacity of at least 352 starts per minute.