---
title: "Building an Auto-Scaling Lambda based on Github's Workflow Job Queue"
description: "ClickHouse replaced CloudWatch-alarm-based EC2 Auto Scaling for its self-hosted GitHub Actions runners with a Lambda that reads the workflow job queue, built from GitHub webhook events stored in ClickHouse, and sets desired capacity directly."
url: "https://swe.quest/articles/building-an-auto-scaling-lambda-based-on-github-s-workflow-job-queue-4077ceef4fa411b3"
canonical: "https://clickhouse.com/blog/building-github-workflow-job-scheduler-using-clickhouse"
source: "ClickHouse"
published: "2023-06-15"
difficulty: "medium"
kind: "Case study"
reading_minutes: 2
tags: ["ci-cd","capacity-planning","cloud","serverless","cost-optimization"]
---

# Building an Auto-Scaling Lambda based on Github's Workflow Job Queue

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-06-15, 2 min read, Case study. Original: [https://clickhouse.com/blog/building-github-workflow-job-scheduler-using-clickhouse](https://clickhouse.com/blog/building-github-workflow-job-scheduler-using-clickhouse)

## Summary

ClickHouse replaced CloudWatch-alarm-based EC2 Auto Scaling for its self-hosted GitHub Actions runners with a Lambda that reads the workflow job queue, built from GitHub webhook events stored in ClickHouse, and sets desired capacity directly. The Lambda compares current runners against in-progress and queued jobs, then scales up by roughly deficit/5 and down by reserve/2. The old rule (add a runner after 5 minutes above 97% busy) took hours to warm up groups of 50+ runners. The new approach launches jobs faster, saves compute when load drops, and keeps busy and active runner counts much more closely aligned.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)

## Prerequisites

- GitHub Actions self-hosted runners ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))
- AWS Auto Scaling Groups ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))
- SQL aggregation ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

ClickHouse, GitHub Actions, AWS Lambda, AWS Auto Scaling Groups, CloudWatch, GitHub Webhooks

## Related posts

- [Using ClickHouse to Monitor Job Queues in GitHub Actions](https://swe.quest/articles/using-clickhouse-to-monitor-job-queues-in-github-actions-98d7a5d7c86849dc.md): ClickHouse · 2023-01-05 · Medium · 3 min read · CI/CD, Observability, Analytics & OLAP, SQL
  GitHub Actions lacks built-in metrics for its workflow job queue, but an organization-level webhook emitting workflow\_job events can feed an AWS Lambda that inserts each event into a ClickHouse MergeTree table.
- [How GitHub uses GitHub Actions and Actions larger runners to build and test GitHub.com](https://swe.quest/articles/how-github-uses-github-actions-and-actions-larger-runners-to-build-and-test-915368ba99ad3985.md): GitHub Engineering · 2023-09-26 · Medium · 8 min read · CI/CD, Developer productivity, Identity & auth, Scaling
  GitHub moved CI for GitHub.com to GitHub Actions on larger runners, peaking at about 4,500 concurrent 32-core runners, 15,000 jobs per hour and 150,000 cores.
- [How we tripled max concurrent jobs to boost performance of GitHub Actions](https://swe.quest/articles/how-we-tripled-max-concurrent-jobs-to-boost-performance-of-github-actions-9d54244cd033cdac.md): GitHub Engineering · 2022-09-16 · Medium · 5 min read · Performance engineering, Scaling, CI/CD, Caching
  GitHub Actions on GitHub Enterprise Server went from 2,200 to 7,000 max concurrent jobs on 96-core machines between GHES 3.2 and 3.6 through three main fixes.
- [Monitor your CI performance using Sentry](https://swe.quest/articles/monitor-your-ci-performance-using-sentry-bda7e20d9e49dda7.md): Sentry · 2026-11-10 · Medium · 4 min read · CI/CD, Observability, Developer productivity
  Sentry's tracing model can represent GitHub Actions workflows as traces, with each job's steps as spans, so slow steps and run-to-run variance show up the same way they would for an API request.
- [Infrastructure Observability for Changing the Spend Curve](https://swe.quest/articles/infrastructure-observability-for-changing-the-spend-curve-815f49a6391b6804.md): Slack Engineering · 2021-10-07 · Medium · 10 min read · CI/CD, Cost optimization, Observability, Resilience, Capacity planning
  Slack bent the growth curve of its webapp CI spend, which had been rising about 10% month over month, by using observability (dashboards, metrics and tracing) to drive three changes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
