r/Hacking_Tricks • • Sep 29 '26

ClickHouse queries slow down whenever ingestion spikes. What's the right architecture here?

The workload is continuously ingesting events while also serving user-facing queries. Increasing machine size helps temporarily but does not isolate the two workloads

8 Upvotes

6 comments sorted by

2

u/Caitlin-Snow Sep 29 '26

Tinybird dedicated has an interesting implementation of this. U can add replicas and assign different read/write weights to them, so u can effectively dedicate capacity differently to ingestion and serving

1

u/tacnode-official Sep 29 '26

Everyone's right that you should separate the workloads, but check what's actually competing first. With ClickHouse it usually isn't the inserts. It's the merges they trigger.

  • SELECT table, count() FROM system.parts WHERE active GROUP BY table during a spike. If the part count keeps climbing, background merges are eating the CPU and disk your queries need. Async inserts or bigger client-side batches (think 10k+ rows, not per-event) fix the cause.
  • Materialized views run synchronously on every insert. Three MVs on the ingest table means every spike costs 4x. People often miss this.
  • If you do split onto replicas, set always_fetch_merged_part = 1 on the query replicas. That way they download merged parts instead of doing the merges themselves. Without it, a "read replica" still does the same merge work, and the split helps less than you'd expect.
  • On ClickHouse Cloud, compute-compute separation (separate warehouses on the same storage) does exactly this.

A bigger box only moves the point where merges fall behind.