Back to Empasy Insights Engineering Note · SyncETA
2026-11-21 (Updated 2026-11-23) • 6 min read • Automated Checks · KEDA Scaling

SyncETA Capacity Scaling (Part 2) — KEDA ScaledObject & Graceful Scale-In for Active Tests

3-Line Executive & Business Summary
  • ChallengeScaling down immediately when the waiting queue hits zero risks killing pods that are still running browser scenarios mid-flight.
  • ApproachSyncETA monitors both BullMQ wait and active keys (bull:scheduler_jobs:wait / active) via KEDA ScaledObject, paired with 180s termination grace periods, SIGTERM draining, and stabilization windows.
  • ImpactWorkers scale out rapidly during release bursts while scaling down gradually only after active scenarios finish and upload evidence cleanly.
Want to verify how this fits your team workflows? Request Consultation
Technical Deep Dive for IT & Engineering Teams

In Part 1, we explained why CPU/memory HPA misfires for isolated browser workers and why Redis queue depth is the right demand signal. In Part 2, we walk through how SyncETA's BullMQ queue (scheduler_jobs) and dedicated worker deployment (APP_ROLE=worker) integrate with KEDA ScaledObject and graceful scale-in controls.

1. SyncETA Worker Runtime & BullMQ Redis Keys

SyncETA runs its API server and workers from the same container image, switching modes via APP_ROLE=worker. In worker mode (worker-main.ts), NestJS boots a headless application context without HTTP overhead so SchedulerJobProcessor consumes jobs from the BullMQ scheduler_jobs queue.

  • Waiting queue (bull:scheduler_jobs:wait): Queued scenarios not yet picked up by a worker.
  • Active queue (bull:scheduler_jobs:active): Scenarios currently executing inside a worker pod's browser and Playwright MCP session.

Monitoring only wait causes premature scale-in as soon as all queued jobs move to active. Watching both wait and active keeps desired replicas aligned with total live workload.

STEP 01
Watch Wait & Active
Polls bull:scheduler_jobs:wait and active list lengths
STEP 02
KEDA Scale-Out
Expands worker pods within min/max replica ceilings
STEP 03
SIGTERM Draining
Stops polling new jobs and completes active browser runs
STEP 04
Safe Scale-In
Removes idle pods after 300s stabilization & 180s grace

2. KEDA ScaledObject & Secret-Backed TriggerAuthentication

Redis credentials remain inside Kubernetes Secret objects referenced through KEDA TriggerAuthentication:

apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: sync-eta-redis-auth
  namespace: sync-eta
spec:
  secretTargetRef:
    - parameter: password
      name: worker-secret
      key: REDIS_PASSWORD
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: sync-eta-worker-scaler
  namespace: sync-eta
spec:
  scaleTargetRef:
    name: worker
  pollingInterval: 15
  cooldownPeriod: 300
  minReplicaCount: 2
  maxReplicaCount: 12
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleUp:
          stabilizationWindowSeconds: 0
          policies:
            - type: Pods
              value: 4
              periodSeconds: 30
        scaleDown:
          stabilizationWindowSeconds: 300
          policies:
            - type: Pods
              value: 1
              periodSeconds: 60
  triggers:
    - type: redis
      metadata:
        address: redis.sync-eta.svc.cluster.local:6379
        listName: bull:scheduler_jobs:wait
        listLength: "1"
      authenticationRef:
        name: sync-eta-redis-auth
    - type: redis
      metadata:
        address: redis.sync-eta.svc.cluster.local:6379
        listName: bull:scheduler_jobs:active
        listLength: "1"
      authenticationRef:
        name: sync-eta-redis-auth

3. Four Safeguards Protecting Active Browser Runs

  1. terminationGracePeriodSeconds: 180: Configured directly on the worker Deployment so in-flight scenarios and .webm video uploads finish before forced termination.
  2. shareProcessNamespace: true: Allows PID 1 inside the pod to reap zombie Chromium child processes cleanly.
  3. Graceful BullMQ Shutdown on SIGTERM: Calling app.close() pauses new job pulls immediately while awaiting completion of the active job.
  4. Node Headroom & Control-Plane Exclusion: nodeAffinity keeps workers off control-plane nodes, while calibrated CPU/memory limits (2.3 CPU / 4Gi RAM) preserve kubelet headroom.

4. Production Verification Checklist

  • Trigger 20 simultaneous scheduled scenarios and observe kubectl get hpa -n sync-eta -w scaling smoothly up to the configured cap.
  • Confirm zero aborted test histories and complete .webm evidence uploads during scale-down windows.
  • Track OOM events and residual Chromium process counts in Prometheus/Grafana.