Skip to content

Topics: what a fit and its reads cost on each span engine

Last updated: 2026-11-25T11:18:34-03:00 (UTC-3)

What Topics costs at a realistic volume, with the spans on PostgreSQL (spans.engine: database) and on the analytics store (analytics_store). Topics, summaries and assignments live in PostgreSQL on both; what changes with the engine is where the per-topic figures and the explorer’s topic term read the traces.

  • A fit is seconds, and it is the gateway’s CPU, not the database’s. Clustering 20,000 summaries of 1,024 dimensions (the default fit_max_summaries) into 40 topics takes 4 to 6 seconds of one core, the two-dimensional projection for the scatter 2.5 to 3 seconds, reading the cohort 0.2 to 0.4 seconds and publishing topics and assignments about 1 second in one transaction. A scheduled refit of a full map is about 10 seconds of work; it runs in the worker, never on a request. These four rows and the serving rule do not depend on the span engine: their two columns are two runs of the same code, and the spread between them is the noise of the machine.
  • Placing a unit that arrives later costs nothing measurable: the serving rule against 40 centroids of 1,024 dimensions takes about 0.01 ms. What a live unit costs is its two model calls.
  • The topics table reads in 85 to 240 ms on PostgreSQL and about 150 ms on the analytics store for 40 topics over 100,000 traces: one grouped read of the trace summaries joined to the assignments. On PostgreSQL the time grows with the window (a third of the traces in 24 hours, all of them in 72); on the analytics store it is flat.
  • The explorer’s topic term is a join, not a list, so it is exact for a topic of any size. A page or a count for one topic over the whole 72 hours takes about 300 ms on PostgreSQL and about 90 ms on the analytics store; combined with a selective term (status:error) PostgreSQL answers in 35 ms. topic.intent:none, an anti-join over every assignment, costs the same as a positive term.
  • The model deployments of a topic (requests, cost and p95 per alias and provider) read the topic’s request spans: about 130 ms on PostgreSQL and 100 ms on the analytics store for a topic of 2,500 units.
  • Mirroring assignments to the analytics store took about 5 seconds for 100,000 rows; in production they are mirrored in the tick that writes them.

Which engine to choose is the trace explorer’s question; Topics does not change the answer. With more than a few hundred thousand traces in the windows you read, the analytics store keeps the topic reads flat.

A probe in the gateway’s own test suite (internal/gateway/topics_probe_test.go, run only on request) writes the same generated traces as the explorer’s probe to one engine through the gateway’s span writers, all of one team. The newest 20,000 traces get a summary with a 1,024-dimension embedding drawn around 40 planted centres (one in fifty is a stray near nothing); the fit runs on them step by step; then every one of the 100,000 traces is assigned to a topic, one in fifty as an outlier. Reads run 20 times after one warm-up, through the functions the API calls; the three steps of the fit that take seconds run 3 times, and the publication once.

  • PostgreSQL 16 in a container, with the span partitions and indexes the gateway creates; VACUUM (ANALYZE) after the load.
  • ClickHouse 25.12 in a container.
  • One Apple M4 Pro machine, the databases in local containers. The figures compare the two engines on the same data; they are not a capacity promise.

The fit found exactly the 40 planted topics on both runs, and both engines answered the same number of rows for every read. The recorded runs are in topics.json.

100,000 traces, 410,078 spans over 72 hours

Section titled “100,000 traces, 410,078 spans over 72 hours”
Read Rows matched or returned PostgreSQL p50 (ms) PostgreSQL p95 (ms) Analytics store p50 (ms) Analytics store p95 (ms)
Fit: read the cohort (20000 summaries of 1024 dimensions) 20,000 221 265 387 467
Fit: cluster the cohort (in the gateway, one core) 40 4,022 4,070 6,027 6,526
Fit: project the cohort to two dimensions 20,000 2,491 2,553 2,891 2,971
Fit: publish 40 topics and 20000 assignments (one transaction) 20,000 753 753 1,290 1,290
Serving rule: place one unit among the topics 1 0.0 0.0 0.0 0.1
Topics table: the figures of 40 topics, last 24 hours 41 85.2 90.2 143 194
Topics table: the same figures, last 72 hours 41 239 278 154 195
Explorer page: topic.id of the largest topic 50 310 502 88.3 128
Explorer count: topic.id of the largest topic 2,500 308 345 93.8 132
Explorer page: topic.intent:outlier 50 318 396 99.6 134
Explorer count: topic.intent:* status:error 2,923 35.2 50.9 166 195
Explorer count: topic.intent:none 0 346 384 152 217
Topic detail: the model deployments of the largest topic 6 134 150 99.5 162

Writing the data took 10 s on PostgreSQL and 4 s on the analytics store; each read ran 20 times after one warm-up.

m7gtwcontact@m7gtw.com