# OTLP ingest: application spans on each span engine

**Last updated:** 2026-11-26T02:16:00-03:00 (UTC-3)

What [application spans over OTLP](/docs/features/otlp-ingest/) cost to store on each span engine, so you can size the ingest and choose `spans.engine` with numbers.

## What the figures say

- **On PostgreSQL an upload of 100 spans takes about 16 ms at the median**, with 8 uploads at once: about 45,000 spans per second from one replica, the database using one to two cores. An OpenTelemetry exporter sends a batch every 5 seconds by default, so one replica absorbs the spans of thousands of instrumented processes.
- **On the analytics store an upload takes about 62 ms at the median** and the same load runs at about 10,700 spans per second, the analytics store using four to five cores. Most of that time is the read of each upload's trace before the write: it is what lets an exporter send a batch again without storing a span twice, and what keeps a connector span whose gateway child is already stored. The analytics store answers that read with a `FINAL` query over the span table.
- **Every upload was stored whole.** No upload failed, and the stored span count equals the spans sent (500,000 plus the warm-up's 100 on PostgreSQL).
- **The bounds hold it.** `otlp_ingest.max_concurrent_uploads` (8 by default) caps what one replica stores at once; past it an upload answers `503 ingest_busy` with `Retry-After`, which exporters retry. Keep the default unless the database has spare cores: raising it moves the queue from the exporters to the database.

Recommended: keep `spans.engine: database` for the ingest unless the analytics store is already your span engine for volume; there the ingest still sustains about 10,000 spans per second per replica.

## Method

A probe in the gateway's own test suite (`internal/gateway/otlp_ingest_bench_test.go`, run only on request with `GATEWAY_TEST_OTLP_LOAD=<uploads>`) builds 5,000 protobuf uploads of 100 spans each, every one a new trace (an `invoke_agent` root, 49 `chat` spans with a model and token counts, 50 `execute_tool` spans), and sends them with 8 goroutines through the gateway's whole handler: authentication of a `traces:write` key, the rate check, decoding, mapping, the per-trace read, the price estimate and the synchronous write. One warm-up upload first creates the day partition and the tables.

- PostgreSQL 16.15 and ClickHouse 25.12 in local containers on one Apple M4 Pro machine; the handler runs in the test process (no network hop between client and gateway).
- Database CPU is from `docker stats` sampled about once a second during the run.
- The figures compare the engines under one load; they are not a capacity promise for other hardware.

The recorded runs are in [otlp-ingest.json](https://github.com/m7gtw/gateway/blob/main/docs/performance/otlp-ingest.json).

<!-- generated by scripts/render-trace-explorer.py from otlp-ingest.json: do not edit below -->

| Engine | Uploads | Spans per upload | Concurrency | Spans per second | Uploads per second | p50 (ms) | p95 (ms) | p99 (ms) | Max (ms) | Database CPU during the run | Failed |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: |
| PostgreSQL | 5,000 | 100 | 8 | 44,751 | 448 | 15.9 | 20.7 | 134 | 268 | PostgreSQL 40 to 175% of one core (docker stats, a second run of the same load) | 0 |
| The analytics store | 5,000 | 100 | 8 | 10,742 | 107 | 62.2 | 161 | 262 | 755 | ClickHouse 400 to 550% of one core; PostgreSQL 3 to 12% | 0 |

<!-- end of generated tables -->
