返回资讯中心
外部精选
软件工程
#开发者实时流

groundcover 用 BucketStreamer 替换 S3Queue 改进 ClickHouse 摄取

来源标题:Building a ClickHouse ingestion service with BucketStreamer

groundcover 构建 BucketStreamer 替换 ClickHouse 内置的 S3Queue,以改进数据摄取并控制批处理与并发。此前其链路让 Vector 直接写入 ClickHouse,出现丢数据后改为用对象存储缓冲、由 S3Queue 加载文件,但文件堆积、插入失败,只能为单个客户手工调参。新方案用于在规模化场景下处理遥测数据。

Hacker News 最新Eyalcohen42026/11/24 · 今天25 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

Blog

Building a ClickHouse Ingestion Service with Bucket Streamer

DevOps

November 24, 2026 • 10 min read

Building a ClickHouse Ingestion Service with Bucket Streamer

How groundcover replaced S3Queue with Bucket Streamer to improve ClickHouse ingestion, control batching and concurrency, and handle telemetry at scale.

Introduction

When you build ingestion for an observability platform, you plan for the worst. When a customer hits an incident, their telemetry can jump 10x, or even 100x, in seconds. That's also exactly when they need their latest data the most.

In the early days of groundcover, we had Vector, an open-source telemetry pipeline, write directly into ClickHouse. Whenever ClickHouse couldn't accept writes, we lost data. Losing data is unacceptable to us, so we put object storage in between as a buffer, and ClickHouse loaded the files itself with S3Queue, its built-in feature for reading files from a bucket.

That solved one part of the problem: preventing data loss while ClickHouse was busy. But files piled up, inserts failed, and we found ourselves tuning database settings by hand for individual customers.

So we built Bucket Streamer, a Go service that moves telemetry from object storage into ClickHouse. Today, it runs across hundreds of groundcover backends and handles gigabytes of compressed telemetry per second.

This post explains why we built it and the engineering decisions behind it.

groundcover runs a bring your own cloud (BYOC) model, so ClickHouse runs inside each customer's cloud account. A heavy query or background process can temporarily prevent it from accepting writes, even for a few seconds.

We always prioritize ingestion over queries because we want the latest data to be available. Even so, ClickHouse can't always keep up with sudden bursts. We needed somewhere for telemetry to wait that could absorb a 100x burst without requiring us to scale anything.

In this architecture, Vector writes compressed files to a bucket in the customer's account (Amazon S3, Google Cloud Storage, or Azure Blob Storage). The files stay there until ClickHouse can take them.

Every ClickHouse insert creates at least one new part on disk. Too many small inserts overwhelm background merges and can trigger "too many parts" errors. Batching combines small files into fewer, larger inserts.

ClickHouse can read those files itself with S3Queue, a table engine that polls a bucket path and tracks which files it has processed.

To be fair, S3Queue carried our ingestion for about two years. But keeping up with our volumes meant constantly tuning its settings by hand.

Most of the tuning came down to batching. Every insert creates at least one new part on disk. When small inserts arrive faster than ClickHouse can merge them, it slows down and eventually rejects inserts with "too many parts" errors.

We were caught between two problems: large batches could run out of memory, while smaller batches created more parts and more pressure on merges. We constantly found ourselves adjusting the limits in each customer's database, often while on call, and eventually maintained a playbook for it. In one incident, roughly 1,000 trace files piled up, and it took about 15 minutes for the data to become queryable.

Adding ClickHouse shards made polling even worse. Every shard independently listed the same bucket and tried to claim the same files. Only one could win each claim, so most requests were wasted. In our measurements, only about 3% of claim attempts succeeded.

Provisioning ClickHouse for the worst possible burst would mean paying for idle capacity in every customer's cloud. Autoscaling wouldn't help much either: a ClickHouse shard pod can take minutes to become ready.

Kafka would add another messaging cluster to every customer's cloud, for a pipeline that runs in a straight line. Our telemetry can tolerate a few seconds of latency, and in our benchmarks, object storage costs a fraction of what Kafka would.

We wanted object storage's buffering benefits without relying on ClickHouse to manage ingestion or introducing another messaging cluster. That meant owning the reader ourselves.

After enough rounds of tuning S3Queue one customer at a time, we decided to own the reader. When we wrote down what we needed, we realized we were building a small messaging system on top of object storage. It had four requirements:

We didn't want to keep track of how many workers were running, whether one or fifty. Instead, Bucket Streamer coordinates the work itself and keeps state outside the workers, in a managed Postgres instance we already operated.

A delivery is one batch on its way to one ClickHouse cluster, pinned to a target shard. A worker claims a delivery, reads its files from object storage, and sends them to ClickHouse as a single insert.

It doesn't need to download the entire batch and unpack it first: Go's io.MultiReader chains the file readers together, passing their contents through sequentially. Since Vector originally writes each file as gzip-compressed data, the worker can concatenate the files into one valid gzip stream without decompressing or inspecting the telemetry.

The same workers can act as the scanner. Each worker tries to acquire a Postgres advisory lock, and whichever gets it runs the scan if one is due.

Imagine a customer with 200 Kubernetes clusters, each depositing a file every second. That's 200 new files every second. If memory allows, we can combine them into one insert. We want large batches because larger inserts mean fewer parts for ClickHouse to manage.

But there's a tradeoff: while a file waits for its batch to fill, the customer can't query that data yet.

We settled on a compromise. The scanner runs every second and handles each signal, such as logs or traces, independently. It releases a signal's new files when they reach 1 MB compressed, or 10 seconds after the previous batch, with a maximum batch size of 10 MB.

This avoids creating too many small inserts while putting a limit on how long telemetry waits before becoming queryable. We also cap each batch at 10 MB to keep individual inserts bounded. We arrived at these thresholds by balancing insert efficiency, memory usage, and how quickly new telemetry becomes queryable.

This gives us control over the tradeoff between insert efficiency and data freshness, without requiring customer-specific tuning.

Workers crash, and someone needs to notice when one dies in the middle of an insert. The classic approach is a heartbeat with a timeout. But two competing requirements make the timeout difficult to choose. A short timeout can hand a slow but healthy job to a second worker. We've seen CPU throttling turn a five-second job into a fifty-second one. A long timeout means a crashed worker's job can sit idle for minutes before another worker picks it up.

Instead of heartbeats, we use Postgres row locking. A worker claims a delivery using SELECT ... FOR UPDATE SKIP LOCKED and keeps both the row lock and its transaction open for the entire insert. If the worker crashes and its database connection closes, Postgres rolls back the transaction, releasing the lock. Another worker can then claim the delivery almost immediately.

If an entire node disappears and the connection doesn't close cleanly, our Postgres configuration terminates the transaction after ten idle minutes, longer than any insert should take.

This lets Postgres handle worker ownership and recovery without a separate heartbeat mechanism.

We were a bit scared of this one at first. Postgres has a poor reputation as a queue, and every insert in flight holds a transaction open. If you need Kafka, you can't take Postgres and scream at it until it becomes Kafka.

We didn't need Kafka, though. Postgres stores only file names and batch state; the telemetry stays in object storage. More traffic also means bigger batches, up to our 10 MB limit.

Before committing, we benchmarked 250 inserts per second. Our busiest backend now handles about 57 inserts and 196 Postgres queries per second at weekday peak, with roughly 750 open transactions.

With heartbeats every five seconds, those transactions would also require 150 writes per second. Our locking approach avoids that additional write load.

An insert can fail when ClickHouse runs short on memory, for example. Bucket Streamer retries with backoff, from one second up to one hour, while the files stay in the bucket.

A worker can also crash after ClickHouse accepts an insert but before it records success. Another worker may then send the same delivery again.

We handle this with ClickHouse insert deduplication. Each insert carries a stable token made from the batch ID and destination ID. ClickHouse uses that token to recognize previously accepted inserts, rather than comparing the inserted rows.

This makes it important that retries are identical. They must send the same files, in the same order, to the same shard. That's why the scanner's batching and routing decisions are final: workers can change, but a delivery must always represent the same insert.

When all deliveries for a batch are complete, a worker moves its files to a processed location. This keeps them out of future scans while preserving the raw data for replay.

Today, across hundreds of groundcover backends, Bucket Streamer:

Bucket Streamer is another service to operate, and it puts Postgres in the ingestion path. If Postgres is down, files wait in the bucket, and we have to pace the recovery ourselves.

In return, we control how files are batched, how deliveries are retried, and how quickly a backlog drains. We also avoid running a separate messaging cluster for every customer.

It's a tradeoff we're comfortable with because object storage already gives us the durability and burst capacity we need. Bucket Streamer gives us control over everything that happens between the bucket and ClickHouse.

In the next posts, we'll cover how we reduced our Postgres connections, kept slower signals from starving the others, and built Bucket Streamer with coding agents.

Until then, come talk to us in our community Slack.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →