Scaling Uptrace

This guide covers how to scale Uptrace for higher ingestion volumes. Work through these steps in order:

  1. Review scaling strategy — vertical first, then horizontal.
  2. Diagnose the bottleneck — buffer-full errors, part counts, CPU.
  3. Tune Uptrace processing pipelines — more threads and larger buffers.
  4. Optimize ClickHouse inserts — async inserts and batching.
  5. Add ClickHouse sharding — when a single node isn't enough.
  6. Consider Kafka — only after exhausting the other options.

For the full list of configuration options, see the configuration reference. Most changes require an Uptrace restart — see upgrading Uptrace for the procedure.

Scaling strategy

Vertical first

According to ClickHouse documentation, prefer vertical scaling over horizontal scaling:

Successful deployments with ClickHouse use servers with hundreds of cores, terabytes of RAM, and petabytes of disk space. Scaling vertically first provides cost efficiency, lower operational overhead, and better query performance.

Horizontal scaling

Uptrace instances are stateless and can be scaled horizontally. Use a load balancer to distribute traffic across instances — each instance should connect to the same PostgreSQL and ClickHouse databases.

Resource requirements

ComponentCPURAMNotes
Uptrace instance2–44–8 GBPer instance behind load balancer
PostgreSQL2–44–8 GBSSD storage recommended
ClickHouseScaleScalePrefer large instances over many small
Redis1–22–4 GBFor caching and session storage

Diagnosing bottlenecks

Before changing configuration, identify the actual bottleneck:

  • Ingest requests rejected with a 429 (the uptrace.pipeline.gate_rejected_requests metric grows) — ingestion is outpacing ClickHouse inserts. Increase max_buffered_bytes or add more processing threads.
  • High active part count (system.parts table) — too many small inserts are creating parts faster than merges can consolidate them. Enable async inserts or increase ch_max_insert_size.
  • High merge activity (system.merges table) — related to high part count. Larger, less frequent inserts reduce merge pressure.
  • Insert latency — slow inserts cause buffers to fill up. Check ClickHouse disk I/O and CPU. SSDs are strongly recommended. Also ensure async_insert is enabled and wait_for_async_insert is set appropriately — synchronous inserts add a flush round-trip to every batch.
  • CPU saturation on the Uptrace host — if all cores are busy, adding more max_threads won't help. Consider moving ClickHouse to a separate server or adding shards.

Uptrace processing pipelines

Uptrace processes telemetry through parallel pipelines — one each for spans, span links, logs, events, and metrics. Each pipeline has its own block under pipelines in the config file (for example, pipelines.spans) with three settings:

SettingWhat it controlsDefault
max_threadsProcessing goroutinesGOMAXPROCS (CPU cores)
max_buffered_bytesIn-memory buffer capmax_threads × 64 MiB, at most ¼ of the memory limit
ch_max_insert_sizeRecords per INSERT batch10000 (varies by pipeline)

max_threads

The number of goroutines that process records and insert them into ClickHouse. Each thread pulls a batch from the in-memory buffer, processes it, and executes a ClickHouse INSERT.

Default: GOMAXPROCS (CPU cores). Increase when CPU is not the bottleneck but insert latency is — for example, when ClickHouse is on a separate server and network round-trips dominate.

yml
pipelines:
  spans:
    max_threads: 16

Setting max_threads higher than the number of CPU cores is safe — the threads spend most of their time waiting on ClickHouse I/O.

max_buffered_bytes

Caps the total estimated bytes held in memory for a pipeline. The fair-share ingest gate (fairshare: true, the default) uses the same budget. As the buffer fills, the gate rejects requests with a retryable 429 Too Many Requests (gRPC: ResourceExhausted), so OTLP clients retry instead of losing data. A request that finds the buffer full waits for room until its deadline, ingest.request_timeout (10s) after it arrived, before Uptrace decodes it, then gets a retryable 429 too. The metric uptrace.pipeline.gate_rejected_requests counts these requests, with the reason hard_full for a full buffer and over_share for a project above its fair share. The client sends the request again, so a full buffer slows ingestion and loses no acknowledged data. One processing queue or Kafka partition that stops draining holds at most half of the buffer. Then every metrics request gets a 429, because the points of a series always go to the same partition, and gate_rejected_requests counts them with the reason partition_full. A request of spans, logs or events gets a 429 only when it has records for that queue or partition, and Uptrace logs ingest request refused: a partition holds half of the buffer and drains nothing. A larger buffer does not fix this: examine the Kafka broker or ClickHouse.

Default: max_threads × 64 MiB. With 16 threads the default buffer is 1 GiB. When the process has a memory limit (a cgroup limit applied through service.memory_limit_ratio, or GOMEMLIMIT), the default is also capped at a quarter of that limit. An explicit max_buffered_bytes is not capped.

The buffer must hold two times the largest record of the pipeline, because one queue or partition holds at most half of it. The minimum is 264192 (258 KiB) for spans, logs, events and metrics, whose records are at most 128 KiB, and 1049600 (about 1 MiB) for profiling. Uptrace does not start with a smaller explicit value, and a memory limit does not cap the default below the minimum. A profile sample or stack row larger than 1 MiB is dropped with each sample that needs it. The request still succeeds, the OTLP response counts a profile that stored nothing as rejected, and Uptrace logs the count as oversized_rows and oversized_stacks.

yml
pipelines:
  spans:
    max_buffered_bytes: 536870912 # 512 MiB

If you see buffer-full errors, ingestion is temporarily outpacing ClickHouse insert speed. Increase the value to absorb bursts without dropping data. As a rough guide, size the buffer for the longest realistic ClickHouse stall (a merge, a brief network hiccup, etc.).

Memory and read slots

The cap on the default buffer is per pipeline, so the sum over all pipelines can still exceed the memory limit. If you set max_buffered_bytes explicitly, keep the sum of all pipelines well below the memory of the host or container.

The OTLP receivers also limit how many request bodies they read and decode at the same time: ingest.max_concurrent_reads, 8 × GOMAXPROCS by default. A request that waits for a slot longer than ingest.read_queue_timeout (1s) gets a retryable 429. Raise max_concurrent_reads only when the host has memory to spare for more large requests in flight.

ch_max_insert_size

The maximum number of records batched into a single ClickHouse INSERT.

yml
pipelines:
  spans:
    ch_max_insert_size: 10000

The right value depends on whether ClickHouse async inserts are enabled:

  • async_insert = 1 (recommended). ClickHouse accumulates inserts into its own buffer and flushes them as larger batches. You can use a smaller ch_max_insert_size (5000–10000) — smaller Uptrace batches flush faster and reduce buffer pressure, while ClickHouse still creates efficiently sized data parts.
  • async_insert = 0. Each Uptrace insert creates a separate data part. Larger values (10000–20000) are important to avoid too many small parts, which increases merge pressure and degrades query performance.

In both cases, very large batches increase per-insert latency and memory usage. Reduce the value if inserts are timing out.

Example: high-volume configuration

The values below assume async_insert = 1 and use more threads and larger buffers than the defaults. The combined buffer totals roughly 2.6 GiB — make sure the host has enough RAM, especially if Uptrace and ClickHouse share the same server.

yml
pipelines:
  spans:
    max_threads: 16
    ch_max_insert_size: 10000
    max_buffered_bytes: 1073741824 # 1 GiB

  span_links:
    max_threads: 2
    ch_max_insert_size: 5000
    max_buffered_bytes: 134217728 # 128 MiB

  logs:
    max_threads: 12
    ch_max_insert_size: 10000
    max_buffered_bytes: 805306368 # 768 MiB

  events:
    max_threads: 4
    ch_max_insert_size: 5000
    max_buffered_bytes: 268435456 # 256 MiB

  metrics:
    max_threads: 8
    ch_max_insert_size: 10000
    max_buffered_bytes: 536870912 # 512 MiB

If many ingest requests get a 429 (uptrace.pipeline.gate_rejected_requests grows), increase max_buffered_bytes for the affected pipeline and add more RAM to the host.

ClickHouse insert tuning

The settings below are ClickHouse server settings. You can set them globally in ClickHouse (users.xml or profiles.xml) or pass them per-query through the Uptrace config:

yml
ch_cluster:
  shards:
    - replicas:
        - addr: localhost:9000
          query_settings:
            async_insert: 1
            wait_for_async_insert: 1
            async_insert_max_data_size: 200000000
            async_insert_busy_timeout_ms: 5000

The async insert buffer flushes when either async_insert_max_data_size or async_insert_busy_timeout_ms is reached — whichever comes first.

async_insert

When enabled (1, recommended), ClickHouse buffers incoming inserts and flushes them as a single batch instead of writing each insert immediately. This reduces the number of data parts created, lowering merge pressure and improving throughput.

wait_for_async_insert

Controls whether ClickHouse acknowledges an insert immediately or waits until the buffer is flushed to disk.

  • wait_for_async_insert: 1. Uptrace waits for the flush to complete. Acknowledged data is guaranteed to be persisted, and insert errors are reported back to Uptrace.
  • wait_for_async_insert: 0. The insert returns as soon as data enters the buffer. Faster, but a ClickHouse crash can lose buffered data, and insert errors are silently ignored.

async_insert_max_data_size

Maximum bytes in the async insert buffer before a flush is triggered.

Default: 100 MiB. Since Uptrace already batches on the client side via ch_max_insert_size, the async buffer is merging a few concurrent batches rather than thousands of tiny inserts. For high-volume deployments, increase to 200–500 MB to create fewer, larger data parts at the cost of more memory on the ClickHouse side.

async_insert_busy_timeout_ms

Maximum time (ms) before the async buffer is flushed, even if it hasn't reached async_insert_max_data_size.

Default: 1000 ms. Increase to 3000–5000 ms to give the buffer more time to fill, resulting in fewer and larger data parts. Lower values reduce the data-loss window when wait_for_async_insert: 0, but create more parts. High-volume deployments generally benefit from longer timeouts.

ClickHouse sharding

For ingestion volumes that exceed a single ClickHouse node, distribute data across multiple shards. Sharding is a Premium feature.

Each shard is an independent ClickHouse node (or replicated set) that stores a portion of the data. Uptrace distributes writes using weighted round-robin.

yml
ch_cluster:
  cluster: 'uptrace1'
  replicated: true
  distributed: true # Required for sharding (Premium only)

  shards:
    - weight: 1
      replicas:
        - addr: clickhouse-1a:9000
          database: uptrace
        - addr: clickhouse-1b:9000
          database: uptrace

    - weight: 1
      replicas:
        - addr: clickhouse-2a:9000
          database: uptrace
        - addr: clickhouse-2b:9000
          database: uptrace

The weight parameter controls write distribution — a shard with weight 2 receives twice as many writes as weight 1. Use this when shards have different hardware capacity.

This configuration tells Uptrace which shards exist. You also need to configure the ClickHouse cluster itself — define the topology in ClickHouse's remote_servers so that ClickHouse knows about all shards and replicas. See the ClickHouse cluster deployment docs for details.

When adding shards to an existing deployment, you don't need to redistribute old data. New writes go to the new shards, and queries automatically span all shards via distributed tables.

Kafka-based ingestion

Kafka-based ingestion is available in every edition, including Community, and needs no license. Releases before v2.1.0-rc.3 also required an Enterprise license to run the worker.

Kafka solves two problems:

  1. Buffering during maintenance. When ClickHouse is down or can't keep up, Kafka retains data until ClickHouse is ready. Without Kafka, Uptrace holds data only in its in-memory buffer (max_buffered_bytes). Once that fills, clients get a retryable 429 and must keep the data until they retry.
  2. Efficient batching. Kafka enables larger, more efficient batches before writing to ClickHouse, improving insert throughput.

That said, Kafka adds operational complexity — evaluate whether the buffering benefits justify the additional infrastructure. Consider it only after exhausting the tuning options above.

Architecture

  1. Uptrace API receives data from clients, validates it, applies rate limits, and writes it to Kafka.
  2. Uptrace Worker consumes the raw data and processes it (sampling, service graph, etc.).
  3. The worker writes the processed rows to ClickHouse, either directly or through a second set of Kafka topics (see Writing ClickHouse through Kafka).
  1. ClientsOTel SDK, Collector
  2. Uptrace APIvalidate, rate-limit
  3. Kafkaraw topics
  4. Uptrace Workersampling, service graph
  5. ClickHouse

Each component scales and fails independently: the API accepts data at line rate, and the worker processes it at its own pace.

Enabling Kafka

Kafka is enabled by configuring brokers. There is no separate on/off switch. As soon as kafka.brokers is non-empty, the API writes telemetry to Kafka instead of to the in-memory buffer, and a separate worker process consumes it.

yml
##
## Kafka transport. The API publishes telemetry here and the worker
## consumes it. Setting at least one broker turns Kafka on.
##
kafka:
  brokers:
    - 'kafka-1:9092'
    - 'kafka-2:9092'

  # Optional SASL authentication.
  # Mechanism: PLAIN, SCRAM-SHA-256, or SCRAM-SHA-512.
  #sasl: SCRAM-SHA-512
  #user: uptrace
  #password: <secret>

  # Optional TLS for broker connections.
  #tls:
  #  ca_file: /etc/uptrace/kafka-ca.pem

  # Producer tuning.
  max_message_bytes: 10485760 # 10 MiB, must fit your largest batch
  linger: 10ms # how long the producer waits to fill a batch
  # How long the producer keeps a record that the broker did not acknowledge.
  # Unset: 2 × ingest.request_timeout for telemetry, no limit for others.
  #delivery_timeout: 30s

  # Emit OpenTelemetry metrics for the Kafka client itself.
  otel_metrics: false

delivery_timeout sets how long the producer keeps a record before it stops trying to send it. When you do not set it, the producers of telemetry records use 2 × ingest.request_timeout (20s by default), and the other producers keep a record until the broker acknowledges it. A pipeline with acks.await: false keeps its records with no limit instead. A telemetry request that awaits the ack answers only after the broker acknowledged its records, so a record that the producer stops sending belongs to a request that got a retryable 429, and the client sends it again. A value that you set, 0s included, applies to every producer. 0s means no limit: while the broker is down, the records stay in the ingest buffer, and the retries of their requests store them two times when the broker comes back. Any other value must be at least 1s. When the producer stops sending a record, it fails all the records that the partition has in flight. The broker can already hold some of them, so a retry can store them two times.

When kafka.brokers is empty (the default), Uptrace runs in-process and writes directly to ClickHouse — no worker and no Kafka required.

If you deploy with Ansible, adding a kafka group to the inventory configures the brokers, turns on writing ClickHouse through Kafka, and starts the worker automatically.

Running the worker

With Kafka enabled, the API only validates and publishes data — a separate worker process drains the Kafka topics and inserts into ClickHouse and PostgreSQL. Run it alongside the main uptrace process:

shell
uptrace --config=/etc/uptrace/config.yml worker

The worker requires Kafka brokers. When kafka.brokers is empty, it exits on startup with worker requires Kafka brokers: set kafka.brokers in the config.

Run as many worker instances as needed to keep up with ingestion; they share the consumer group and partition the load automatically.

When a Kafka partition has no leader, for example while the only broker of a topic with one replica restarts, Uptrace keeps the records for that partition in its buffer. When they fill half of the buffer, metrics requests get a retryable 429 until the partition has a leader again. A topic with more than one replica keeps a leader through the restart of one broker.

Per-pipeline Kafka settings

Each pipeline has a kafka block for its own Kafka clients:

yml
pipelines:
  spans:
    kafka:
      # Run this pipeline's consumer in the worker. Set to false to stop
      # consuming while the API keeps writing to the topic.
      consumer: true
      # Decoded fetch bytes the consumer buffers ahead of processing.
      # 0 uses the default of 256 MiB.
      consumer_max_buffered_bytes: 0
      # Consumer lag (messages) per partition above which monitors skip
      # an evaluation, to avoid alerts on incomplete data.
      lag_threshold: 100000
      # Producer buffer toward the click_* topics. Used only with
      # ch_cluster.kafka.enabled. 0 uses the default of 256 MiB.
      ch_max_buffered_bytes: 0

Each pipeline's consumer holds its own consumer_max_buffered_bytes, so size the worker's memory from the sum over the pipelines it runs.

Kafka acknowledgements

Each ingest pipeline (spans, logs, events, metrics, profiling) sets the Kafka acknowledgement of its records, and whether a request waits for it:

yml
pipelines:
  metrics:
    acks:
      # Which replicas must hold a record before the broker acknowledges it:
      # all (every in-sync replica, the default) or leader.
      required: all
      # Wait for the ack before the request answers. Default: true.
      await: true

The defaults keep every acknowledged record: a request answers a success only after every in-sync replica holds its records, within ingest.request_timeout, and a late ack answers a retryable 429. One slow follower, for example a replica in another datacenter, then holds up every request with a record on its partition, and the retries store the records that the broker takes late two times. Two options trade durability for latency:

  • required: leader takes the followers out of the ack path. It turns off idempotent producing, because Kafka allows it only with all. A record that the leader acknowledged and no follower copied yet is lost when the leader fails, a batch whose response was lost is written again on retry, and the retried batches of a partition may land out of order. A repeated delta counter or histogram point then counts two times, and a log, event or span link shows two times.
  • await: false answers a request once the producer accepts its records, without waiting for the ack. The producer still asks for the acks that required names, and keeps each record until it is delivered, with no time limit unless kafka.delivery_timeout sets one. A slow partition then costs latency and buffer instead of 429s and duplicates, and a request gets a 429 only when the buffer is full. The records of answered requests that the producer still holds, up to the pipeline's buffer, are lost when the process crashes, is killed for memory, or stops before the broker takes them.

acks applies only with Kafka. Span links follow the spans pipeline. A trace request waits for the streams whose pipeline awaits the ack and not for the others. The service-graph, usage and click_* producers always wait for every in-sync replica.

To keep a slow follower in another datacenter out of the ack path without these costs, keep each partition in one zone with a single-zone placement rule instead.

Kafka placement

kafka.placement states which brokers may hold the replicas of which topics, and which topics keep each partition in one zone. Kafka cannot store these rules, so uptrace kafka rebalance places the replicas by them, and uptrace kafka check-placement checks the cluster against them and prints the commands that fix it.

yml
kafka:
  placement:
    classes:
      fast:
        brokers: [1, 2, 3, 4, 5, 6]
        bandwidth: 10gbit # each broker gets replicas and leaders in proportion to it
    topics:
      # A regexp over the whole topic name, without the deployment prefix.
      # The first rule that matches a topic decides.
      - match: '.*'
        classes: [fast]
        # Keep every replica of each partition in one zone.
        single_zone: true

The zone of a broker is its broker.rack up to the first -, for example fsn1 for fsn1-dc22. With single_zone: true, acks: all waits for no follower in another datacenter, but a partition is offline while its zone is down. rebalance refuses a broker without a rack as the target of a single-zone topic. Each worker reports messaging.kafka.placement.misplaced_replicas and messaging.kafka.placement.split_partitions; alert on max() above 0.

Older releases used flat keys such as kafka_consumer, kafka_consumer_max_buffered_bytes, kafka_lag_threshold, and ch_kafka_max_buffered_bytes. They still work with a deprecation warning; run uptrace config fix to move them into the kafka block.

Writing ClickHouse through Kafka

By default, the worker inserts the processed rows directly into ClickHouse. Set ch_cluster.kafka.enabled to write them through Kafka instead:

yml
ch_cluster:
  kafka:
    # Write the processed rows through Kafka. Needs kafka.brokers.
    enabled: true
    # Memory for the fetched records of one worker, over all tables.
    # 0: a quarter of the memory limit (GOMEMLIMIT), or an eighth of
    # the host memory when there is no limit.
    max_worker_buffered_bytes: 0

The worker then encodes the rows of each table into ClickHouse blocks and produces them to one topic per table and shard, click_<table>_shard<N>, on the kafka.brokers cluster. A topic consumer inside the worker reads these topics and inserts each batch into the table on its shard. While ClickHouse is down or slow, the worker keeps processing, and only the inserts of rows that are already processed wait in Kafka. When ClickHouse comes back, the backlog drains in large inserts.

Each insert carries a deduplication token made from its Kafka offsets. A retry, a failover to another replica, a rebalance, or a crash of the worker sends the same block with the same token, so a replicated table stores it once. Use this path with replicated tables (ch_cluster.replicated: true). A non-replicated table keeps no tokens and can store a retried block twice.

Uptrace no longer uses the ClickHouse Kafka engine. ClickHouse does not connect to Kafka, so it needs no broker settings, and uptrace migrate up drops the <table>_queue tables and their materialized views that older releases created. The uptrace ch kafka_create, kafka_drop, kafka_create_view, and kafka_drop_view commands are removed.

Older releases turned this path on with a ch_cluster.kafka.brokers list. Uptrace reads such a section as enabled: true and ignores the brokers. Run uptrace config fix to rewrite it.

Tuning the ClickHouse inserts

Each table under ch_schema has a kafka block for its topic consumer, so you can tune high-volume tables independently. The values below are the defaults:

yml
ch_schema:
  spans_index:
    kafka:
      # Longest a fetch waits for min_fetch_bytes: the age of the oldest
      # row of a partial block. 1m for the *_index_sample tables.
      flush_interval: 7.5s
      # A fetch of one partition returns early once it holds this much.
      min_fetch_bytes: 16777216 # 16 MiB
      # Largest fetch of one partition, and so the largest insert.
      max_fetch_bytes: 67108864 # 64 MiB
      # Fetch budget of the table on one shard. Raise it to let more
      # partitions insert at once, so a backlog drains faster.
      max_buffered_bytes: 67108864 # 64 MiB
      # Most records (blocks) in one insert.
      max_batch_records: 65536
      # Time limit of the first insert attempt of a small batch. A batch
      # gets more time for its bytes, and each retry gets more.
      insert_timeout: 5s
      # Per-partition consumer lag (messages) above which the pipeline is
      # treated as stale, so monitors defer the current evaluation until
      # the consumer catches up (avoids alerting on incomplete data).
      lag_threshold: 100

Raise min_fetch_bytes and flush_interval on high-volume tables to create fewer, larger data parts, at the cost of more memory and a longer delay before rows appear. Keep max_buffered_bytes at least max_fetch_bytes.

The Kafka engine settings of older releases (kafka_max_block_size, kafka_poll_timeout, kafka_poll_max_batch_size, kafka_thread_per_consumer, kafka_handle_error_mode, and kafka_skip_broken_messages) are ignored. kafka_lag_threshold and kafka_flush_interval still work with a deprecation warning, and uptrace config fix moves them into the kafka block.