The Solution: The autoscaler is a Python service (FastAPI) that consumes GitHub workflow_job webhook events and drives ASG desired capacity. It maintains queue and rate signals in Redis, using a reactive-plus-predictive sizing model: queue depth, job arrival rate, estimated runner startup time, and a configurable multiplier. The controller runs on an APScheduler loop that reconciles ASG capacity against Redis state, with throttling-aware intervals to avoid AWS API limits.
The instance orchestrator runs on each machine. On startup, it loads AWS config via boto3, constructs the host abstraction (with atexit Terminate() for failure cleanup), initializes a Docker client and systemd-backed runner service. It pulls CI credentials from Secrets Manager, randomly selects from multiple service accounts for rate-limit distribution, authenticates with container registries, then starts the runner. When a job begins, the orchestrator detaches the instance from the ASG (preventing new job assignments) and when the job completes, it terminates the instance — true ephemeral runners.
The resource monitor is a sidecar Python process using psutil that collects CPU, memory, disk, and network metrics, submitting them to Datadog via the datadog library. It provides fleet-wide visibility into resource utilization and abuse patterns.
The AMI layer uses Packer templates with a centralized version file as the single source of truth for runner binaries. AMI build commits are recorded in version-tracking files, and Terraform references these SHAs for immutable, rollback-friendly deployments. The CI pipeline bakes AMIs, commits version bumps, and Atlantis autoplan triggers for staging/production rollout.