The pipeline-side fixes are the ones that remove the cause. Their names differ between products, so look for the retry, concurrency, batch and buffer settings of your shipper.
Duplicate rows
Every hop that delivers at least once can create copies. ClickHouse removes only the copies that it can recognize: a retry of the sameINSERT with the same data. A copy that an earlier hop re-sent arrives inside a different batch and is inserted again:
- Find the hop that makes the copies. If every hop adds its own metadata to the event (a processing time, a worker id), compare the copies of one id. Copies that differ in the metadata of the last hop were made before it. Copies that are identical in every column were re-sent by the last hop.
- Acknowledge upstream early. When the central processor confirms a batch to the edge shipper only after the insert into ClickHouse, every slow insert makes the edge re-send. A durable queue on the input of the processor removes this dependency.
- Keep retries identical. Insert deduplication works for a table that keeps a deduplication log:
Replicated*MergeTreetables do by default, a plainMergeTreetable needsnon_replicated_deduplication_windowas in the example. Since ClickHouse 26.2 it also covers asynchronous inserts by default. It only helps if the shipper re-sends the same rows in the same request. - Deduplicate by id. For exact results, store the events in a
ReplacingMergeTreetable whose sorting key contains the id, hereORDER BY (service, timestamp, event_id), and read it withFINALor with thefinalsetting set to1. Merges remove the copies in the background at an unknown time, andFINALmakes reads more expensive, so decide whether your dashboards need it.
Retry storms
A retry storm starts when inserts become slow, for example because the server is short of memory or busy with merges:- Requests time out in the shipper, and it sends them again while the first attempts are still running.
- Every running insert occupies one slot of the server limit
max_concurrent_queries. In ClickHouse Cloud the limit is 1000 concurrent queries per replica. - When all slots are taken, new queries fail with the error
TOO_MANY_SIMULTANEOUS_QUERIES(code 202,Too many simultaneous queries. Maximum: 1000). The shipper retries them too, so the load grows while nothing completes. Dashboards and your own diagnostic queries are rejected as well.
- In the shipper, limit the number of concurrent requests to ClickHouse and retry with exponential backoff, in particular after
TOO_MANY_SIMULTANEOUS_QUERIES(202) andMEMORY_LIMIT_EXCEEDED(241). - In ClickHouse, insert as a dedicated user and set
max_concurrent_queries_for_userfor it, well below the limit of the server. Then the shipper alone can’t take all slots:
clusterAllReplicas(default, system.query_log) instead of system.query_log to see all replicas.
Bad timestamps
One row that can’t be parsed or stored fails the insert. A batch of the usual size for a shipper is a single block, and a block is written entirely or not at all, so the whole batch is rejected. The shipper then retries a batch that can never succeed, and the share of failing requests grows. A large insert that is split into several blocks, or into several partitions, can fail after earlier blocks are already stored, see the conditions for an atomic insert; a retry of such a request inserts those rows again unless they are deduplicated. Two errors come from event timestamps:DateTime64, so milliseconds and nanoseconds are out of range. Before 26.8 such a number was read as a count of ticks of the column (nanoseconds for DateTime64(9)); input_format_read_datetime_number_as_raw_value restores that.
The second error comes from events dated 1970 or months in the past, which spread one batch over many partitions:
exception column of system.query_log, to tell the two apart.
The fix belongs in the pipeline: convert the timestamp to ISO 8601 or to epoch seconds, drop or clamp values outside a sensible window around the current time, and route what remains to a dead-letter output where you can see it. Settings of the inserting user can bridge the time until then:
input_format_allow_errors_numandinput_format_allow_errors_ratioskip rows of text formats that can’t be parsed, such as"timestamp": "yesterday". They don’t skip a number that is out of range (DECIMAL_OVERFLOW), and the skipped rows are lost.- Setting
throw_on_max_partitions_per_insert_blockto0writes the batch and logs a warning instead of throwing the exception. The 150 rows above then become 150 parts in 150 partitions, so remove the setting once the pipeline is fixed.
Batch small requests on the server
Shippers send many small requests. With asynchronous inserts (enabled by default since ClickHouse 26.2) the server collects them in a buffer and writes the buffer when the first of these limits is reached:
The timeout is adaptive: frequent inserts raise it step by step from
async_insert_busy_timeout_min_ms (default 50) to the maximum. Every flush writes at least one part per partition, so a steady stream with the default timeouts creates several small parts per second. Higher timeouts in the profile of the inserting user, as in log_ingest above, give fewer and larger parts. With wait_for_async_insert = 1 the client gets its answer only after the flush, so set the request timeout of the shipper well above async_insert_busy_timeout_max_ms.
To check how often buffers are flushed and which timeout was used: