Quick revision
The short answer
Every INSERT into a MergeTree table writes at least one new data part, and background merges combine parts into larger ones; when a partition has more active parts than the parts_to_throw_insert threshold, ClickHouse rejects inserts with a too many parts error. Five thousand single-row inserts a second create parts far faster than merges can combine them. The fix is to batch: thousands to hundreds of thousands of rows per insert about once a second, through a buffer in the service, Kafka, or async_insert, and to check that the partition key does not multiply parts.
What to remember
In this answer, we saw that every INSERT into a MergeTree table creates a new immutable part, background merges combine parts, and too many active parts per partition makes ClickHouse delay and then reject inserts with a too many parts error. Five thousand single-row inserts a second create parts far faster than merges can handle. The fix is batching, thousands of rows per insert about once a second through a service buffer or Kafka, or async_insert with a deliberate choice about waiting for the flush, plus a partition key that does not multiply parts.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Every INSERT into a MergeTree table writes at least one new data part, and background merges combine parts into larger ones; when a partition has more active parts than the parts_to_throw_insert threshold, ClickHouse rejects inserts with a too many parts error. Five thousand single-row inserts a second create parts far faster than merges can combine them. The fix is to batch: thousands to hundreds of thousands of rows per insert about once a second, through a buffer in the service, Kafka, or async_insert, and to check that the partition key does not multiply parts.
Why this question is asked
ClickHouse is extremely fast at analytics, and teams adopting it often write to it the way they would write to PostgreSQL, one row per event. It works in testing and fails in production with an error that sounds like a capacity problem but is really a usage problem. Interviewers ask this because the explanation requires understanding the MergeTree storage engine, and because the fixes involve real trade-offs around acknowledgement and durability. In this answer, we will recap how MergeTree stores data, see why single-row inserts overwhelm it, fix ingestion with batching, look at async inserts and what waiting for them means, and check the partition key, ending with the follow-up about not waiting for flushes.
1A Quick Recap of MergeTree Parts
A MergeTree table stores data in parts. Each part is an immutable directory on disk holding the rows of one insert, sorted by the table's ORDER BY key, with one compressed file per column (or a compact single file for small parts) and a sparse primary index. Sorting and compressing within a part is what makes ClickHouse scans so fast.
Because parts are immutable, every INSERT creates at least one new part, one per partition the inserted rows touch. In the background, merges combine several small parts of the same partition into one larger, sorted part, much like compaction in an LSM tree. A query has to read every active part in the partitions it touches, so ClickHouse wants a modest number of large parts.
2How Single-Row Inserts Produce the Error
Five thousand single-row inserts per second from 30 pods create about 5,000 new parts per second. Each part, however tiny, costs a directory, several files, an fsync, metadata in memory and later a merge. Merges cannot combine parts nearly that fast, so the count of active parts in the current partition climbs. ClickHouse protects itself with two thresholds: above parts_to_delay_insert it slows inserts down, and above parts_to_throw_insert it rejects them with a TOO_MANY_PARTS error saying merges are processing significantly slower than inserts. The thresholds have changed between versions, so check the values in yours.
So the cluster is not too small. It is spending its IO and CPU creating and merging thousands of tiny parts, which is pure overhead, while the same data in a few large inserts would be cheap.
- Pod inserts one row5,000 times per second in total
- Each insert writes a new partfiles, fsync, metadata
- Background merges combine partsfar slower than 5,000 per second
- Active parts above parts_to_delay_insert?YesInserts are slowedNoContinue
- Active parts above parts_to_throw_insert?YesTOO_MANY_PARTS: insert rejectedNoInsert accepted
5 steps in order. Play them, or step through them one at a time.
3Fix 1: Batch the Writes
ClickHouse wants inserts of thousands to hundreds of thousands of rows, roughly once per second per table or less often. The simplest way is a buffer in each service: collect events in memory and flush when the batch reaches, say, 50,000 rows or one second has passed, whichever comes first. With 30 pods that is about 30 inserts a second in total instead of 5,000, and each creates a part worth merging.
A buffer in the pod loses its contents if the pod crashes, so many teams put a durable log in between. The service publishes events to Kafka, and either ClickHouse's Kafka table engine with a materialised view, or a connector such as the ClickHouse Kafka Connect sink, reads them and writes large batches. Kafka keeps the events until they are written, so a crash means a retry, not a loss.
| Ingestion | Inserts per second | New parts per second |
|---|---|---|
| Single-row inserts from 30 pods | about 5,000 | about 5,000 |
| Buffer per pod, flush every 1 s | about 30 | about 30 |
| Kafka plus one batching writer | 1 to 2 | 1 to 2 |
4Fix 2: Let the Server Batch With async_insert
If changing the clients is hard, ClickHouse can batch for us. With async_insert enabled, the server accepts small inserts into an in-memory buffer per table and writes them as one part when the buffer reaches a size or a time limit. The important setting is wait_for_async_insert. When it is 1, the client's insert returns only after its data has been flushed to a part, so the acknowledgement still means the data is stored, at the cost of the client waiting up to the flush interval. When it is 0, the insert returns as soon as the data is buffered, which is faster but means the client cannot know whether the write survived.
5Fix 3: Check the Partition Key
Every insert creates one part per partition it touches, and merges never combine parts across partitions. A table partitioned by hour has 24 times as many partitions per day as one partitioned by day, and one partitioned by a high-cardinality column such as customer id can turn one insert into thousands of parts. For event data, monthly or daily partitions are typical, and the fine-grained ordering belongs in the ORDER BY key, not the partition key. We can check active parts per partition in system.parts to see whether the layout is part of the problem.
6Follow-up questions
What do you lose if clients do not wait for async inserts to be flushed?
The acknowledgement stops meaning stored. With wait_for_async_insert = 0, the server replies once the rows are in its memory buffer, so if the server crashes or restarts before the flush, those rows are lost and the client already moved on. Errors in the data, such as a type mismatch, are also not reported to the client that sent them. For click analytics, losing a second of events in a rare crash may be acceptable; for anything that must be complete, wait for the flush or use a durable log like Kafka in front.
Why not just raise parts_to_throw_insert?
That only moves the wall. Thousands of tiny parts still waste IO and CPU, slow queries that must open every part, and leave merges permanently behind. The threshold is a safety valve; the fix is fewer, larger inserts.
Is the Buffer table engine still a good option?
It is an older way to batch inside ClickHouse, kept in memory and lost on a crash. Async inserts are the recommended approach for server-side batching in current versions, but check the documentation for your version.
7Conclusion
In this answer, we saw that every INSERT into a MergeTree table creates a new immutable part, background merges combine parts, and too many active parts per partition makes ClickHouse delay and then reject inserts with a too many parts error. Five thousand single-row inserts a second create parts far faster than merges can handle. The fix is batching, thousands of rows per insert about once a second through a service buffer or Kafka, or async_insert with a deliberate choice about waiting for the flush, plus a partition key that does not multiply parts.
Open with
In ClickHouse, a MergeTree table stores data as immutable parts. Every INSERT writes at least one new part per partition it touches, sorted and compressed by column, and background merges combine small parts into larger ones.
Then, if they want more
If a partition gets more active parts than parts_to_delay_insert, inserts are slowed, and past parts_to_throw_insert they are rejected with the too many parts error, which says merges are slower than inserts; the exact thresholds depend on the version.
Here, 30 pods doing single-row inserts create about 5,000 parts a second, which no merge process can keep up with, so the cluster burns IO and CPU on tiny parts. The fix is to batch. Each pod can buffer rows and insert every second or every 50,000 rows, which drops us to about 30 inserts a second.
Better, publish events to Kafka and let the Kafka engine or a sink connector write large batches, so a pod crash does not lose data. If the clients cannot change, async_insert lets the server batch small inserts; I would keep wait_for_async_insert on so an acknowledgement still means the data is stored.
I would also check the partition key: hourly partitions or a high-cardinality column multiply parts, so daily or monthly partitions are typical.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain how MergeTree storage leads to this error and how you would fix the ingestion.": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/1dce8be4eb/