Skip to content

feat(sink): write events directly to ClickHouse - #5

Merged
gagantrivedi merged 11 commits into
mainfrom
clickhouse-sink
Oct 30, 2026
Merged

gagantrivedi merged 11 commits into
mainfrom
clickhouse-sink

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Writes events straight to ClickHouse, batched in memory and flushed on a configurable interval, instead of going through Kafka.

  • Make SinkError sink-agnostic
  • Reject events older than 10 days (bounds the daily partitions one insert can touch)
  • Batched ClickHouse sink (SINK=clickhouse)
  • ClickHouse integration tests + CI service

@gagantrivedi
gagantrivedi force-pushed the clickhouse-sink branch 2 times, most recently from 91ca8f6 to 828a26d Compare October 28, 2026 08:59
@gagantrivedi
gagantrivedi changed the base branch from generic-sink to main October 28, 2026 08:59
Bounds how many daily ClickHouse partitions one insert can touch, so a
batch with scattered old timestamps cannot fail or overload the insert.

Refs #3
SINK=clickhouse buffers accepted events in memory and writes them with
one plain INSERT per flush, every SINK_FLUSH_INTERVAL_MS or earlier at
SINK_BATCH_MAX_ROWS. Requests return 202 once buffered; a full buffer
(SINK_BUFFER_MAX_BYTES) returns 503. Failed writes are retried, then
dropped. The batching is generic so other sinks can reuse it.

Refs #3
Tests the ClickHouse sink against a real server: flushed rows land in
the events table and read back intact, and shutdown writes buffered
rows. CI runs a clickhouse-server service for them.

Refs #3
EventRecord owns its fields, so BatchingSink buffers records directly and
sizes them with one approx_size. BatchWriter shrinks to write(), and the
ClickHouse writer builds borrowed rows at flush time. Kafka's wire bytes
are unchanged.

Refs #3
It configures the writer, not a sink, and reads oddly next to
config::SinkConfig.

Refs #3
Byte estimates of parsed JSON were guesswork. The buffer is now
unbounded: put never waits or fails, and the flusher takes the whole
buffer every SINK_FLUSH_INTERVAL_MS, or once SINK_FLUSH_MAX_EVENTS
(5000) events are waiting, as one INSERT. This drops
SINK_BATCH_MAX_ROWS, SINK_BUFFER_MAX_BYTES and SinkError::BufferFull.

Refs #3
Drop comments that restate the code, inline json_column, rename value_column to value_to_text, and prefix the sink and config tests with test_.

Refs #3
@gagantrivedi
gagantrivedi force-pushed the clickhouse-sink branch 2 times, most recently from ba59c6b to 110323e Compare October 28, 2026 10:44
Rename parse_positive to positive_env_var and have it read the variable itself, so callers name it once.

Refs #3
@gagantrivedi
gagantrivedi marked this pull request as ready for review October 28, 2026 10:52
@gagantrivedi
gagantrivedi requested a review from Zaimwa9 October 28, 2026 10:52
Comment thread src/sink/batching.rs Resolved
Comment thread src/sink/mod.rs Resolved
Comment thread src/sink/batching.rs Resolved
Wait 1, 2, 4, 5, 5 s between attempts before dropping a batch, so
writes survive a ClickHouse restart instead of giving up after about
1.4 s. The delays are a fixed list; jitter is dropped, since each
process has a single flusher.

Refs #3
Zaimwa9
Zaimwa9 previously approved these changes Oct 30, 2026

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

…tartup

Classify write errors as transient, bad data or config. Transient errors
are retried; bad data and config errors drop the batch at once. A config
error also fails /health until restart. At startup, check that ClickHouse
is reachable and the table matches the row, so bad credentials or a
missing table fail before serving.

Refs #3
@gagantrivedi
gagantrivedi merged commit c6c8c7f into main Oct 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants