Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 9 min read Case study mediumAdept

Smarter Auto-Scaling for ClickHouse: The Two-Window Approach

ClickHouse Cloud replaced its single 30-hour lookback window for vertical auto-scaling with a two-window recommender. A 3-hour window drives fast scale-downs, and a 30-hour window drives single-step scale-ups to the longer-term peak. A merge table chooses between the windows, and a hunting check compares the current and previous small-window recommendations so allocation doesn't flip-flop when usage is rising. The old fixed 2x/0.5x CPU thresholds caused cascading scale-ups and oscillations, so they were replaced with target-tracking. Target-tracking scales to peak usage divided by a target utilization set at the geometric mean of the watermarks, which makes scaling reversible and prevents allocation drift. Scale-down latency fell from 30 hours to 3 hours, with fewer oscillations and lower infrastructure cost.

Related posts

  • Fixed cadence to seconds: making ClickHouse Cloud autoscaling more reactive

    ClickHouse mediumAdept

    ClickHouse Cloud's vertical autoscaling recommender moved from a fixed timer loop to a controller-runtime based design, so services that hit memory pressure get a recommendation in seconds instead of waiting for the next scheduled pass. Two sources, a slotted periodic sweep and a reactive poller, feed one rate-limited work queue. The queue provides deduplication, exponential backoff, bounded concurrency and leader election without custom code. The reactive signals live in ClickHouse: a materialized view filters breach rows such as soft memory rejections out of the Prometheus metrics firehose into a small TTL'd table ordered by timestamp, which is polled every few seconds with a cheap five-minute window query.

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

    ClickHouse mediumAdept

    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.

  • How Modal uses ClickHouse to power real-time observability for AI workloads

    ClickHouse mediumAdept

    Modal powers three customer-facing observability dashboards (function scaling, per-call timeline, latency percentiles) from a single ClickHouse Cloud table ingesting 1–2 million events per minute and holding ~500 billion logs. Function-call lifecycle events (queued, executing, finished) stream through Kafka and ClickPipes into a ReplacingMergeTree table keyed on function_id, function_call_id and event_at, with ULIDs enabling primary-key range queries. Queries reconstruct call state with GROUP BY function_call_id and argMaxIf for the latest status, and compute P50/P90/P99 queue and execution latency directly with quantile functions. The team reached this scale without indexes, projections or materialized views, and is only now starting latency optimizations.

  • Make Before Break - Faster Scaling Mechanics for ClickHouse Cloud

    ClickHouse mediumAdept

    ClickHouse Cloud replaced rolling-restart vertical scaling with Make-Before-Break (MBB) scaling: new, correctly sized replicas are added before old ones are removed. This avoids multi-hour resizes, since graceful eviction can wait up to 60 minutes per pod for long-running queries. It also avoids overloading the surviving replicas while one is out of rotation. Ordinal-based StatefulSets cannot remove arbitrary pods, so the operator was refactored to run one StatefulSet per server pod (MultiSTS). Existing services were migrated live through a dedicated migration controller, a mutex so only one controller reconciles a resource at a time, a partial maintenance mode, and Temporal workflows that batch and track thousands of migrations.

  • How SolarWinds uses ClickHouse BYOC for real-time observability at scale

    ClickHouse mediumAdept

    SolarWinds ingests about 3 million telemetry messages per second, roughly 550 MB/s with 1 GB bursts, into ClickHouse ReplacingMergeTree tables. Its hottest data, the most recent 60 minutes, suffered when merges lagged behind ingestion. Reducing index granularity, verified by A/B testing a mirrored table through an internal query router, cut five-minute-window query latency from 76 ms to 28 ms. The tradeoffs were primary-key index memory growing from 10 GB to as much as 320 GB and merge times rising nearly 50%. Switching file reads from pread_threadpool to pread on fast SSDs added further gains, and the team moved to ClickHouse BYOC on AWS for S3-backed storage, compute-compute separation and lower operational overhead.

The quest for software engineering knowledge.

Look:
Layout: