# Analytics store: ClickHouse against PostgreSQL

**Last updated:** 2026-11-21T03:33:23-03:00 (UTC-3)

Whether an optional ClickHouse read store would pay off for request logs, usage analytics and trace correlation (task T019.001). PostgreSQL stays the source of truth either way. The tables are generated from [`analytics-store.json`](https://github.com/m7gtw/gateway/blob/main/docs/benchmarks/analytics-store.json) by `scripts/bench-analytics-store.py`; the prose around them is written by hand.

## Method

- **Engines:** PostgreSQL 16.15 (`postgres:16.15-alpine`, the digest the deployment profiles pin) and ClickHouse 25.12.11.4 (`clickhouse/clickhouse-server:25.12`), each in its own container with `--cpus 4 --memory 6g`. Only the engine being measured runs: ClickHouse is stopped while PostgreSQL is measured, and PostgreSQL is stopped once ClickHouse has copied the rows. Docker host: OrbStack on an Apple M4 Pro (12 cores, 11.7 GiB for containers).
- **PostgreSQL settings:** `shared_buffers=1536MB`, `effective_cache_size=4GB`, `work_mem=64MB`, `maintenance_work_mem=1GB`, `max_wal_size=8GB`, `max_parallel_workers_per_gather=4`, `random_page_cost=1.1` (the usual value on SSDs), and `--shm-size 2g`. The schema is the product's own: the gateway binary migrated the empty database, so `gateway_usage_events` has its 30 columns and all 13 product indexes, including the GIN index on `tags`.
- **ClickHouse table:** one first design, not tuned. It is a `MergeTree` with all 30 columns, monthly partitions and `ORDER BY (occurred_at, id)`, with `LowCardinality` for the dimension columns, `Map` for the tags and bloom-filter skip indexes on `request_id` and `trace_id`. `OPTIMIZE FINAL` runs after loading.
- **Data:**
  - PostgreSQL generates the events deterministically, in time order (as a deployment writes them before any retention delete), over the 91 days before 2026-11-01 00:00 UTC. ClickHouse copies the same rows from it.
  - There are 500 keys. Each key belongs to one of 300 principals, and each principal to one of 50 teams. A key mostly uses one operation and up to three neighbouring models out of 40, which run on 8 providers.
  - 95% of requests succeed, 30% of events carry an end user and 20% carry a session. Every trace has one event.
- **Windows:** 7, 30 and 90 days ending at 2026-10-31 12:00 UTC, so the rollup path also reads its two partial days from raw events, as the product does with `to` set to now.
- **Queries:**
  - The PostgreSQL statements are the product's own (`internal/store/analytics.go`, `postgres.go` and `rollup_reads.go`). They run as prepared statements with custom plans (`plan_cache_mode=force_custom_plan`), which is PostgreSQL's best case.
  - The ClickHouse statements are written to return the same rows.
  - The `rollup_*` rows are the product's opt-in rollup reads (`analytics_rollup_reads`, off by default). Beyond seven days they answer from the daily rollups for complete days and from raw events for the edges, without a p95.
  - The analytics view runs its statements in sequence under one 5 s deadline (`internal/gateway/admin.go`). With the shipped configuration (`analytics_comparison` and `analytics_status_breakdown` on) they are the summary, the timeline, six rankings, the 50 most recent events, the status panel and a previous-period summary for the comparison panel. The view table adds up the first ten. The status panel always reads raw events, even with rollup reads on, and so do views of seven days and less. The previous-period summary was not measured; it costs about one more summary.
- **Timing:** measured by each client inside its container (`psql \timing` and `clickhouse-client --time`, the latter with 1 ms resolution). Each statement runs twice. When both runs take under 10 s, it runs five more times and the table shows the median of the last four; otherwise it shows the second run.
- **Answers:** each ClickHouse answer is compared with PostgreSQL's, row by row, in each engine's own order.
  - Counts, sums, names and timestamps must be equal.
  - Only averages and percentiles (doubles) may differ, by at most a relative 1e-9 (`equal_within_1e-9`).
  - Log pages and lookups compare the timestamp, request or trace ID and status of every row.
  - Rollup summaries are checked against the raw summary.
- **Insert cost:** an in-engine copy of the first 1M events into an empty table of the same definition, selected on each engine's key (the primary key in PostgreSQL, the sort key in ClickHouse). In PostgreSQL that table carries every product index. It is not the gateway's write path, which inserts one event per request together with its quota ledger.

## Findings

- **Analytics view as shipped, raw events (the default):**
  - In PostgreSQL, the ten measured statements of one view took 0.2, 1.0 and 3.7 s at 1M events for 7, 30 and 90 days.
  - At 10M, the 7-day view took 3.1 s, but the 30- and 90-day views took 12.9 and 47.3 s. Both are past the 5 s deadline, so the product would answer 503.
  - At 50M, every window is past it: 13.9, 72 and 301 s.
  - ClickHouse answered the same views, p95 included, in 39–122 ms at 1M, 98–592 ms at 10M and 0.3–2.9 s at 50M. With the previous-period summary added, its 50M 90-day view comes to about 3.2 s.
- **With rollup reads on** (`analytics_rollup_reads`, opt-in), the rollup part of a 30- or 90-day view took at most 0.1 s at 1M, 0.5 s at 10M and 1.0 s at 50M, raw edges included, without p95. The whole view is slower, though, because the status panel and every view of seven days or less still read raw events:
  - at 10M: 3.1, 1.6 and 3.1 s for 7, 30 and 90 days, within the deadline;
  - at 50M: 13.9, 6.4 and 35.6 s, all past it.
  - Rollups compressed 5.8:1 at 1M, 24:1 at 10M and 68:1 at 50M. That depends on these 500 keys: a deployment with many more keys compresses less.
- **What rollups do not answer** over 30 and 90 days: p95, rankings by end user or tag, and the tag filter. These took 0.06–0.55 s in PostgreSQL at 1M, 0.9–4.0 s at 10M and 3.4–35 s at 50M. ClickHouse took 6–24 ms, 25–170 ms and 0.1–0.83 s.
- **Top 100 and top 1,000** by principal or key over 90 days, from raw events, took 0.5–0.6 s, 5.7–12 s and 23–36 s in PostgreSQL. ClickHouse took 14 ms, 66–80 ms and 0.3 s. Rollups carry these two dimensions, so they could serve longer rankings too, but that path was not measured.
- **A narrow filter** (one team and one model), from raw events, took 7–24 ms at 1M, 22–600 ms at 10M and 0.15–23 s at 50M in PostgreSQL. ClickHouse took 3.5–9 ms, 9.5–50 ms and 24–241 ms. With rollup reads on, the 30- and 90-day versions would read rollups, which carry both dimensions; that path was not measured with filters.
- **Logs and correlation split by query.**
  - PostgreSQL was faster on index-friendly pages and lookups: 0.06–3 ms against 2.5–7 ms in ClickHouse. These cover the first page, the 50 recent events, a team's errors, a page at offset 10,000, a trace and a request ID. ClickHouse's numbers there are mostly its per-query floor of about 3 ms, and both are interactive.
  - A sparse 90-day filter (status 502, one provider and one operation) went the other way: 22 ms, 352 ms and 12.5 s in PostgreSQL against 5, 20.5 and 30 ms in ClickHouse. At 50M that page is past the logs endpoint's own 5 s deadline, so the product would answer 503.
- **Storage:** ClickHouse used 7.9–8.1× less disk than the PostgreSQL table and indexes: 3.37 GiB against 27.21 GiB at 50M. As a read store it is added on top, because PostgreSQL keeps every event.
- **Insert cost:** copying 1M events in-engine took 12.9–16.2 s in PostgreSQL, with the 13 product indexes, against 0.42–0.70 s in ClickHouse.
- **Same answers:** all 52 compared statements returned the same rows, in the same order, at every volume, and the rollup summaries matched the raw ones.

## Recommendation

- **Proceed with T019.** As shipped, PostgreSQL's analytics view already misses its 5 s deadline for 30 and 90 days at 10M events (about 110,000 a day). Rollup reads fix that at 10M, without p95 beyond seven days. At 50M every view misses the deadline even with rollup reads on, because the 7-day view and the status panel read raw events. ClickHouse answered every view at 50M, p95 included, in at most 2.9 s measured, about 3.2 s with the estimated comparison summary.
- **Below about 10M events in 90 days,** PostgreSQL with rollup reads on stayed within the deadline for every window: 3.1 s at most, plus the comparison summary. That was on this hardware (4 CPUs and 6 GiB), with one view at a time and no concurrent writes. Such a deployment needs no second store.
- **Request logs and correlation (owner decision, 2026-11-07):** they keep reading PostgreSQL by default, and ClickHouse can take them over as a separate choice from analytics. PostgreSQL stays faster for exact lookups and index-friendly pages; ClickHouse was much faster for the sparse filter over a long window, which at 50M PostgreSQL could not answer within the logs deadline.

## Limits

- **Scope:** one machine, one sample per volume, one synthetic distribution, and one ClickHouse design that was not tuned.
- **PostgreSQL as the product ships it:** no partitioning and no BRIN index; with the heap now in time order, a BRIN index on `occurred_at` becomes viable, but it was not measured.
- **Memory:** at 50M, the PostgreSQL table and indexes (27 GiB) exceed the container's 6 GiB.
- **PostgreSQL's layout is its best case:** a fresh heap in perfect time order, indexes built in bulk, just vacuumed, with no retention deletes, bloat or page reuse. In steady state, retention deletes free pages that new rows reuse, so the time order would degrade.
- **Plans:** custom plans are PostgreSQL's best case. The product's statement cache can switch to generic plans, which may be slower.
- **Timing:** ClickHouse values have 1 ms resolution and include a client floor of about 3 ms.
- **What the view totals are:** sums of median statement times, run in sequence as the product does, including the status panel and excluding the comparison panel's previous-period summary.
- **What the insert row is:** a bulk in-engine copy, not the gateway's per-request write path or the replication T019 would need.

## Results

<!-- generated by scripts/bench-analytics-store.py from analytics-store.json: do not edit below -->

### 1,000,000 events

| | PostgreSQL | ClickHouse |
|---|---:|---:|
| Storage on disk | 0.54 GiB (table 0.24, indexes 0.30) | 0.07 GiB |
| Daily rollups (`analytics_rollups`) | 42.6 MiB, 173,619 rows | — |
| Insert 1M events in-engine (ms) | 12,881 (all 13 product indexes) | 703 |

| Analytics view as shipped, without the comparison summary (sum of 10 statements, ms) | 7 days | 30 days | 90 days |
|---|---:|---:|---:|
| PostgreSQL, raw events (default) | 217 | 988 | 3,671 |
| PostgreSQL, rollup reads on (7 days and the status panel stay raw) | 217 | 159 | 471 |
| ClickHouse | 38.5 | 63.5 | 122 |

| Query | Group | PostgreSQL ms | ClickHouse ms | PostgreSQL ÷ ClickHouse | Same answer |
|---|---|---:|---:|---:|---|
| `summary_7d` | aggregate | 14.1 | 4.0 | 3.5× | equal |
| `timeline_7d` | aggregate | 21.9 | 4.0 | 5.5× | equal_within_1e-9 |
| `by_model_7d` | breakdown | 24.5 | 4.0 | 6.1× | equal_within_1e-9 |
| `by_provider_7d` | breakdown | 23.4 | 4.0 | 5.9× | equal_within_1e-9 |
| `by_principal_7d` | breakdown | 31.0 | 4.0 | 7.7× | equal_within_1e-9 |
| `by_team_7d` | breakdown | 26.7 | 4.0 | 6.7× | equal_within_1e-9 |
| `by_key_id_7d` | breakdown | 32.1 | 4.0 | 8.0× | equal_within_1e-9 |
| `by_operation_7d` | breakdown | 21.2 | 4.0 | 5.3× | equal_within_1e-9 |
| `by_status_7d` | breakdown | 21.5 | 4.0 | 5.4× | equal_within_1e-9 |
| `by_end_user_7d` | breakdown | 29.8 | 6.0 | 5.0× | equal_within_1e-9 |
| `by_tag_app_7d` | breakdown | 28.6 | 6.0 | 4.8× | equal_within_1e-9 |
| `recent_7d` | recent | < 1 | 2.5 | 0.07× | equal |
| `filter_team_model_7d` | filtered | 6.8 | 3.5 | 1.9× | equal_within_1e-9 |
| `filter_tag_env_7d` | filtered | 15.8 | 7.0 | 2.3× | equal_within_1e-9 |
| `summary_30d` | aggregate | 60.7 | 6.0 | 10.1× | equal_within_1e-9 |
| `timeline_30d` | aggregate | 97.9 | 7.5 | 13.1× | equal_within_1e-9 |
| `by_model_30d` | breakdown | 113 | 7.0 | 16.2× | equal_within_1e-9 |
| `by_provider_30d` | breakdown | 102 | 7.0 | 14.6× | equal_within_1e-9 |
| `by_principal_30d` | breakdown | 149 | 7.0 | 21.3× | equal_within_1e-9 |
| `by_team_30d` | breakdown | 124 | 6.0 | 20.6× | equal_within_1e-9 |
| `by_key_id_30d` | breakdown | 155 | 7.0 | 22.1× | equal_within_1e-9 |
| `by_operation_30d` | breakdown | 91.9 | 6.0 | 15.3× | equal_within_1e-9 |
| `by_status_30d` | breakdown | 93.5 | 7.0 | 13.4× | equal_within_1e-9 |
| `by_end_user_30d` | breakdown | 118 | 11.0 | 10.7× | equal_within_1e-9 |
| `by_tag_app_30d` | breakdown | 135 | 9.0 | 15.0× | equal_within_1e-9 |
| `recent_30d` | recent | < 1 | 3.0 | 0.04× | equal |
| `filter_team_model_30d` | filtered | 11.9 | 5.0 | 2.4× | equal_within_1e-9 |
| `filter_tag_env_30d` | filtered | 64.6 | 11.5 | 5.6× | equal_within_1e-9 |
| `rollup_summary_30d` | rollup | 5.4 | — | — | equal |
| `rollup_timeline_30d` | rollup | 8.0 | — | — | — |
| `rollup_by_model_30d` | rollup | 7.3 | — | — | — |
| `rollup_by_provider_30d` | rollup | 7.0 | — | — | — |
| `rollup_by_principal_30d` | rollup | 13.7 | — | — | — |
| `rollup_by_team_30d` | rollup | 7.3 | — | — | — |
| `rollup_by_key_id_30d` | rollup | 10.0 | — | — | — |
| `rollup_by_operation_30d` | rollup | 6.8 | — | — | — |
| `summary_90d` | aggregate | 182 | 11.0 | 16.5× | equal |
| `timeline_90d` | aggregate | 403 | 17.0 | 23.7× | equal_within_1e-9 |
| `by_model_90d` | breakdown | 392 | 12.0 | 32.7× | equal_within_1e-9 |
| `by_provider_90d` | breakdown | 425 | 12.0 | 35.5× | equal_within_1e-9 |
| `by_principal_90d` | breakdown | 479 | 14.0 | 34.2× | equal_within_1e-9 |
| `by_team_90d` | breakdown | 417 | 12.5 | 33.3× | equal_within_1e-9 |
| `by_key_id_90d` | breakdown | 615 | 14.0 | 43.9× | equal_within_1e-9 |
| `by_operation_90d` | breakdown | 380 | 13.0 | 29.2× | equal_within_1e-9 |
| `by_status_90d` | breakdown | 378 | 13.0 | 29.1× | equal_within_1e-9 |
| `by_end_user_90d` | breakdown | 212 | 20.5 | 10.3× | equal_within_1e-9 |
| `by_tag_app_90d` | breakdown | 554 | 20.0 | 27.7× | equal_within_1e-9 |
| `recent_90d` | recent | < 1 | 3.0 | 0.06× | equal |
| `filter_team_model_90d` | filtered | 24.3 | 9.0 | 2.7× | equal_within_1e-9 |
| `filter_tag_env_90d` | filtered | 168 | 24.0 | 7.0× | equal |
| `rollup_summary_90d` | rollup | 7.6 | — | — | equal |
| `rollup_timeline_90d` | rollup | 13.4 | — | — | — |
| `rollup_by_model_90d` | rollup | 11.6 | — | — | — |
| `rollup_by_provider_90d` | rollup | 10.7 | — | — | — |
| `rollup_by_principal_90d` | rollup | 13.4 | — | — | — |
| `rollup_by_team_90d` | rollup | 11.6 | — | — | — |
| `rollup_by_key_id_90d` | rollup | 13.7 | — | — | — |
| `rollup_by_operation_90d` | rollup | 10.6 | — | — | — |
| `top100_principal_90d` | top_n | 482 | 13.5 | 35.7× | equal_within_1e-9 |
| `top1000_principal_90d` | top_n | 486 | 13.5 | 36.0× | equal_within_1e-9 |
| `top100_key_id_90d` | top_n | 613 | 14.0 | 43.8× | equal_within_1e-9 |
| `top1000_key_id_90d` | top_n | 612 | 14.0 | 43.7× | equal_within_1e-9 |
| `log_first_page_90d` | logs | < 1 | 3.0 | 0.06× | equal |
| `log_team_errors_30d` | logs | < 1 | 5.0 | 0.07× | equal |
| `log_rare_filter_90d` | logs | 22.5 | 5.0 | 4.5× | equal |
| `log_offset_10000_90d` | logs | 2.9 | 4.0 | 0.72× | equal |
| `log_trace_90d` | correlation | < 1 | 3.0 | 0.04× | equal |
| `request_lookup` | correlation | < 1 | 3.0 | 0.02× | equal |

### 10,000,000 events

| | PostgreSQL | ClickHouse |
|---|---:|---:|
| Storage on disk | 5.43 GiB (table 2.45, indexes 2.98) | 0.68 GiB |
| Daily rollups (`analytics_rollups`) | 104.3 MiB, 417,849 rows | — |
| Insert 1M events in-engine (ms) | 14,173 (all 13 product indexes) | 424 |

| Analytics view as shipped, without the comparison summary (sum of 10 statements, ms) | 7 days | 30 days | 90 days |
|---|---:|---:|---:|
| PostgreSQL, raw events (default) | 3,071 | 12,868 (over the 5 s budget) | 47,334 (over the 5 s budget) |
| PostgreSQL, rollup reads on (7 days and the status panel stay raw) | 3,071 | 1,625 | 3,080 |
| ClickHouse | 98.0 | 258 | 592 |

| Query | Group | PostgreSQL ms | ClickHouse ms | PostgreSQL ÷ ClickHouse | Same answer |
|---|---|---:|---:|---:|---|
| `summary_7d` | aggregate | 147 | 8.5 | 17.3× | equal |
| `timeline_7d` | aggregate | 312 | 11.0 | 28.4× | equal_within_1e-9 |
| `by_model_7d` | breakdown | 363 | 10.0 | 36.3× | equal_within_1e-9 |
| `by_provider_7d` | breakdown | 331 | 9.5 | 34.9× | equal_within_1e-9 |
| `by_principal_7d` | breakdown | 474 | 11.0 | 43.1× | equal_within_1e-9 |
| `by_team_7d` | breakdown | 395 | 11.0 | 35.9× | equal_within_1e-9 |
| `by_key_id_7d` | breakdown | 491 | 13.0 | 37.8× | equal_within_1e-9 |
| `by_operation_7d` | breakdown | 296 | 12.0 | 24.7× | equal_within_1e-9 |
| `by_status_7d` | breakdown | 260 | 9.0 | 28.9× | equal_within_1e-9 |
| `by_end_user_7d` | breakdown | 256 | 16.5 | 15.5× | equal_within_1e-9 |
| `by_tag_app_7d` | breakdown | 439 | 15.5 | 28.3× | equal_within_1e-9 |
| `recent_7d` | recent | < 1 | 3.0 | 0.06× | equal |
| `filter_team_model_7d` | filtered | 22.2 | 9.5 | 2.3× | equal_within_1e-9 |
| `filter_tag_env_7d` | filtered | 150 | 16.5 | 9.1× | equal |
| `summary_30d` | aggregate | 948 | 25.0 | 37.9× | equal_within_1e-9 |
| `timeline_30d` | aggregate | 1,087 | 28.5 | 38.2× | equal_within_1e-9 |
| `by_model_30d` | breakdown | 1,630 | 27.0 | 60.4× | equal_within_1e-9 |
| `by_provider_30d` | breakdown | 1,181 | 26.0 | 45.4× | equal |
| `by_principal_30d` | breakdown | 2,186 | 31.5 | 69.4× | equal_within_1e-9 |
| `by_team_30d` | breakdown | 1,763 | 27.0 | 65.3× | equal_within_1e-9 |
| `by_key_id_30d` | breakdown | 1,888 | 33.5 | 56.4× | equal_within_1e-9 |
| `by_operation_30d` | breakdown | 1,043 | 28.5 | 36.6× | equal_within_1e-9 |
| `by_status_30d` | breakdown | 1,140 | 27.5 | 41.5× | equal_within_1e-9 |
| `by_end_user_30d` | breakdown | 1,248 | 46.0 | 27.1× | equal_within_1e-9 |
| `by_tag_app_30d` | breakdown | 1,572 | 46.0 | 34.2× | equal_within_1e-9 |
| `recent_30d` | recent | < 1 | 3.0 | 0.04× | equal |
| `filter_team_model_30d` | filtered | 127 | 22.5 | 5.7× | equal |
| `filter_tag_env_30d` | filtered | 883 | 57.0 | 15.5× | equal |
| `rollup_summary_30d` | rollup | 53.5 | — | — | equal |
| `rollup_timeline_30d` | rollup | 64.3 | — | — | — |
| `rollup_by_model_30d` | rollup | 61.6 | — | — | — |
| `rollup_by_provider_30d` | rollup | 60.1 | — | — | — |
| `rollup_by_principal_30d` | rollup | 61.8 | — | — | — |
| `rollup_by_team_30d` | rollup | 61.4 | — | — | — |
| `rollup_by_key_id_30d` | rollup | 62.4 | — | — | — |
| `rollup_by_operation_30d` | rollup | 60.1 | — | — | — |
| `summary_90d` | aggregate | 2,105 | 56.5 | 37.2× | equal |
| `timeline_90d` | aggregate | 2,053 | 61.0 | 33.7× | equal_within_1e-9 |
| `by_model_90d` | breakdown | 7,642 | 60.0 | 127.4× | equal_within_1e-9 |
| `by_provider_90d` | breakdown | 3,451 | 61.0 | 56.6× | equal_within_1e-9 |
| `by_principal_90d` | breakdown | 11,940 | 64.0 | 186.6× | equal_within_1e-9 |
| `by_team_90d` | breakdown | 8,767 | 61.0 | 143.7× | equal_within_1e-9 |
| `by_key_id_90d` | breakdown | 5,568 | 66.0 | 84.4× | equal_within_1e-9 |
| `by_operation_90d` | breakdown | 3,227 | 76.5 | 42.2× | equal_within_1e-9 |
| `by_status_90d` | breakdown | 2,582 | 82.5 | 31.3× | equal_within_1e-9 |
| `by_end_user_90d` | breakdown | 3,979 | 121 | 32.9× | equal_within_1e-9 |
| `by_tag_app_90d` | breakdown | 2,899 | 113 | 25.7× | equal_within_1e-9 |
| `recent_90d` | recent | < 1 | 3.5 | 0.05× | equal |
| `filter_team_model_90d` | filtered | 600 | 50.0 | 12.0× | equal |
| `filter_tag_env_90d` | filtered | 2,259 | 170 | 13.3× | equal_within_1e-9 |
| `rollup_summary_90d` | rollup | 43.2 | — | — | equal |
| `rollup_timeline_90d` | rollup | 71.4 | — | — | — |
| `rollup_by_model_90d` | rollup | 62.8 | — | — | — |
| `rollup_by_provider_90d` | rollup | 60.7 | — | — | — |
| `rollup_by_principal_90d` | rollup | 68.6 | — | — | — |
| `rollup_by_team_90d` | rollup | 61.6 | — | — | — |
| `rollup_by_key_id_90d` | rollup | 68.3 | — | — | — |
| `rollup_by_operation_90d` | rollup | 60.8 | — | — | — |
| `top100_principal_90d` | top_n | 12,007 | 65.5 | 183.3× | equal_within_1e-9 |
| `top1000_principal_90d` | top_n | 12,028 | 65.5 | 183.6× | equal_within_1e-9 |
| `top100_key_id_90d` | top_n | 5,653 | 67.0 | 84.4× | equal_within_1e-9 |
| `top1000_key_id_90d` | top_n | 5,652 | 79.5 | 71.1× | equal_within_1e-9 |
| `log_first_page_90d` | logs | < 1 | 4.0 | 0.06× | equal |
| `log_team_errors_30d` | logs | < 1 | 6.0 | 0.06× | equal |
| `log_rare_filter_90d` | logs | 352 | 20.5 | 17.2× | equal |
| `log_offset_10000_90d` | logs | 3.0 | 4.5 | 0.66× | equal |
| `log_trace_90d` | correlation | < 1 | 3.0 | 0.04× | equal |
| `request_lookup` | correlation | < 1 | 3.0 | 0.02× | equal |

### 50,000,000 events

| | PostgreSQL | ClickHouse |
|---|---:|---:|
| Storage on disk | 27.21 GiB (table 12.30, indexes 14.92) | 3.37 GiB |
| Daily rollups (`analytics_rollups`) | 184.9 MiB, 732,130 rows | — |
| Insert 1M events in-engine (ms) | 16,156 (all 13 product indexes) | 674 |

| Analytics view as shipped, without the comparison summary (sum of 10 statements, ms) | 7 days | 30 days | 90 days |
|---|---:|---:|---:|
| PostgreSQL, raw events (default) | 13,861 (over the 5 s budget) | 72,311 (over the 5 s budget) | 301,416 (over the 5 s budget) |
| PostgreSQL, rollup reads on (7 days and the status panel stay raw) | 13,861 (over the 5 s budget) | 6,431 (over the 5 s budget) | 35,618 (over the 5 s budget) |
| ClickHouse | 300 | 975 | 2,910 |

| Query | Group | PostgreSQL ms | ClickHouse ms | PostgreSQL ÷ ClickHouse | Same answer |
|---|---|---:|---:|---:|---|
| `summary_7d` | aggregate | 1,031 | 37.5 | 27.5× | equal |
| `timeline_7d` | aggregate | 1,260 | 31.5 | 40.0× | equal_within_1e-9 |
| `by_model_7d` | breakdown | 1,578 | 33.0 | 47.8× | equal_within_1e-9 |
| `by_provider_7d` | breakdown | 1,386 | 31.5 | 44.0× | equal_within_1e-9 |
| `by_principal_7d` | breakdown | 2,142 | 36.5 | 58.7× | equal_within_1e-9 |
| `by_team_7d` | breakdown | 1,702 | 27.5 | 61.9× | equal_within_1e-9 |
| `by_key_id_7d` | breakdown | 2,210 | 34.0 | 65.0× | equal_within_1e-9 |
| `by_operation_7d` | breakdown | 1,218 | 34.0 | 35.8× | equal_within_1e-9 |
| `by_status_7d` | breakdown | 1,335 | 32.0 | 41.7× | equal_within_1e-9 |
| `by_end_user_7d` | breakdown | 637 | 61.0 | 10.4× | equal_within_1e-9 |
| `by_tag_app_7d` | breakdown | 1,848 | 53.0 | 34.9× | equal_within_1e-9 |
| `recent_7d` | recent | < 1 | 3.0 | 0.05× | equal |
| `filter_team_model_7d` | filtered | 153 | 23.5 | 6.5× | equal |
| `filter_tag_env_7d` | filtered | 1,036 | 67.0 | 15.5× | equal |
| `summary_30d` | aggregate | 4,683 | 106 | 44.0× | equal |
| `timeline_30d` | aggregate | 5,039 | 96.5 | 52.2× | equal_within_1e-9 |
| `by_model_30d` | breakdown | 8,987 | 97.0 | 92.6× | equal_within_1e-9 |
| `by_provider_30d` | breakdown | 8,163 | 100 | 81.6× | equal_within_1e-9 |
| `by_principal_30d` | breakdown | 11,264 | 108 | 104.8× | equal_within_1e-9 |
| `by_team_30d` | breakdown | 9,465 | 99.5 | 95.1× | equal_within_1e-9 |
| `by_key_id_30d` | breakdown | 11,631 | 106 | 109.7× | equal_within_1e-9 |
| `by_operation_30d` | breakdown | 7,650 | 130 | 58.8× | equal_within_1e-9 |
| `by_status_30d` | breakdown | 5,431 | 129 | 42.1× | equal_within_1e-9 |
| `by_end_user_30d` | breakdown | 3,356 | 200 | 16.8× | equal_within_1e-9 |
| `by_tag_app_30d` | breakdown | 5,770 | 186 | 30.9× | equal_within_1e-9 |
| `recent_30d` | recent | < 1 | 3.0 | 0.05× | equal |
| `filter_team_model_30d` | filtered | 1,500 | 81.5 | 18.4× | equal_within_1e-9 |
| `filter_tag_env_30d` | filtered | 5,651 | 282 | 20.0× | equal |
| `rollup_summary_30d` | rollup | 114 | — | — | equal |
| `rollup_timeline_30d` | rollup | 127 | — | — | — |
| `rollup_by_model_30d` | rollup | 129 | — | — | — |
| `rollup_by_provider_30d` | rollup | 126 | — | — | — |
| `rollup_by_principal_30d` | rollup | 126 | — | — | — |
| `rollup_by_team_30d` | rollup | 126 | — | — | — |
| `rollup_by_key_id_30d` | rollup | 127 | — | — | — |
| `rollup_by_operation_30d` | rollup | 124 | — | — | — |
| `summary_90d` | aggregate | 26,684 | 322 | 82.7× | equal |
| `timeline_90d` | aggregate | 32,986 | 277 | 119.1× | equal_within_1e-9 |
| `by_model_90d` | breakdown | 34,583 | 302 | 114.7× | equal_within_1e-9 |
| `by_provider_90d` | breakdown | 36,299 | 304 | 119.4× | equal |
| `by_principal_90d` | breakdown | 34,216 | 309 | 110.7× | equal_within_1e-9 |
| `by_team_90d` | breakdown | 32,984 | 299 | 110.3× | equal_within_1e-9 |
| `by_key_id_90d` | breakdown | 34,623 | 311 | 111.3× | equal_within_1e-9 |
| `by_operation_90d` | breakdown | 34,263 | 392 | 87.4× | equal_within_1e-9 |
| `by_status_90d` | breakdown | 34,778 | 390 | 89.2× | equal |
| `by_end_user_90d` | breakdown | 19,290 | 554 | 34.9× | equal_within_1e-9 |
| `by_tag_app_90d` | breakdown | 35,249 | 559 | 63.1× | equal_within_1e-9 |
| `recent_90d` | recent | < 1 | 4.0 | 0.04× | equal |
| `filter_team_model_90d` | filtered | 23,438 | 241 | 97.3× | equal_within_1e-9 |
| `filter_tag_env_90d` | filtered | 26,094 | 830 | 31.4× | equal |
| `rollup_summary_90d` | rollup | 70.7 | — | — | equal |
| `rollup_timeline_90d` | rollup | 126 | — | — | — |
| `rollup_by_model_90d` | rollup | 104 | — | — | — |
| `rollup_by_provider_90d` | rollup | 101 | — | — | — |
| `rollup_by_principal_90d` | rollup | 112 | — | — | — |
| `rollup_by_team_90d` | rollup | 106 | — | — | — |
| `rollup_by_key_id_90d` | rollup | 114 | — | — | — |
| `rollup_by_operation_90d` | rollup | 106 | — | — | — |
| `top100_principal_90d` | top_n | 32,260 | 299 | 107.9× | equal_within_1e-9 |
| `top1000_principal_90d` | top_n | 23,167 | 306 | 75.7× | equal_within_1e-9 |
| `top100_key_id_90d` | top_n | 30,418 | 312 | 97.7× | equal_within_1e-9 |
| `top1000_key_id_90d` | top_n | 35,685 | 314 | 113.6× | equal_within_1e-9 |
| `log_first_page_90d` | logs | < 1 | 4.0 | 0.05× | equal |
| `log_team_errors_30d` | logs | < 1 | 7.0 | 0.06× | equal |
| `log_rare_filter_90d` | logs | 12,527 | 30.0 | 417.6× | equal |
| `log_offset_10000_90d` | logs | 2.9 | 4.0 | 0.73× | equal |
| `log_trace_90d` | correlation | < 1 | 3.0 | 0.04× | equal |
| `request_lookup` | correlation | < 1 | 3.0 | 0.02× | equal |

<!-- end of generated tables -->

## Through the gateway (T019.006)

The tables above time the engines alone. This section runs the gateway itself (the binary of this repository, with the [analytics store](/docs/features/analytics-store/) of T019.002–.005) and times what an operator sees: the admin endpoints of the Usage and Logs pages, with each store; the cost of the copy on the inference path; the copy lag; and the resources of both engines. The tables are generated from [`gateway-store.json`](https://github.com/m7gtw/gateway/blob/main/docs/benchmarks/gateway-store.json) by `scripts/bench-gateway-store.py`.

### Method

- **Same data and engines as above:** the T019.001 events (500 keys, 50 teams, 40 models, 91 days), PostgreSQL 16.15 and ClickHouse 25.12.11.4, each in its own container with `--cpus 4 --memory 6g` and the same PostgreSQL settings; rollups built for every complete day.
- **The gateway** runs as a native process on the host (not pinned), with the shipped analytics features on (`usage_analytics`, `analytics_comparison`, `analytics_status_breakdown`, `usage_tags`, `end_user_tracking`, `session_tracking`, `request_log_status_code`, `request_timing`, `durable_usage`, `usage_valuation`) and one of three read modes: **PostgreSQL as shipped**; **PostgreSQL with rollup reads** (`analytics_rollups`, `analytics_rollup_reads`); **ClickHouse** (`analytics_store_usage`, `analytics_store_request_logs`), measured once the copy, which the gateway itself filled from PostgreSQL, was current.
- **Endpoints:** each is called once to warm up and then seven times on one keep-alive connection with an administrator session; the tables show p50 and p95 of the seven (p95 of seven runs is the slowest one) and the status when it was not 200. The analytics view includes, as shipped, the comparison summary and the status panel; a view past its 5 s deadline answers 503.
- **Same answer:** every answer that ClickHouse gave (by its `read_store`) is compared with PostgreSQL's answer as shipped: every count, sum, name, order and timestamp equal, doubles within a relative 1e-9, with `read_store` and `rollup_coverage` left out; "equal" means all of them matched. Request lookups and session summaries stay on PostgreSQL in every mode.
- **Inference path:** an instant simulated provider (`gwbench -mock`) and `gwbench` at c=32 on one key, with the 1M events stored: three alternating rounds per condition (copy on, copy off, ...), each a fresh gateway, a 2,000-request warm-up and 50,000 measured Chat Completions requests; the table shows the median and the range of the rounds. Gateway CPU per request is the process's CPU time (`ps`, macOS) over the round divided by the answers; peak RSS, the engines' memory and `/api/v1/admin/analytics-store` are sampled in both conditions (the interval is in the table); PostgreSQL and ClickHouse CPU come from their cgroups. The copy lag is `lag_seconds`, which moves in steps of the copy interval (2 s by default), so its small values mostly measure that interval.
- **Outage:** load at c=8 throughout, timed in chunks of 5,000 requests; ClickHouse is paused (`docker pause`) for 60 s and resumed. During the pause and until the copy is current again, the Usage view (7 days) and a log page are read every 2 s and their status, store and latency recorded. Catch-up is the time from the resume until the copy is current with a lag under 5 s.
- **Resources:** engine memory is the cgroup's `memory.current` (page cache included), and CPU the cgroup's usage; "at rest" is 10 s with the copy current and no reads. Disk is `pg_total_relation_size` and ClickHouse's active parts. The host is macOS; the gateway, the load generator and the mock share its CPUs with the engines' virtual machine, so these are absolute numbers of this machine, not of a dedicated server.

### Findings through the gateway

- **Usage view at 1M events** (p50): PostgreSQL as shipped took 0.30 s for 7 days, 1.7 s for 30 and 4.6 s for 90, where some runs already passed the 5 s deadline (503). With rollup reads: 0.32, 0.39 and 1.5 s. ClickHouse: 58, 124 and 166 ms.
- **Usage view at 10M events:** PostgreSQL as shipped took 3.6 s for 7 days and answered 503 for 30 and 90 days in every run. Rollup reads answered 30 days in 2.8 s and still timed out at 90. ClickHouse answered 7, 30 and 90 days in 148, 425 and 848 ms.
- **Rankings and filters over 90 days at 10M:** the end-user and tag rankings and the tag filter timed out in both PostgreSQL modes; ClickHouse answered in 1.0 s and 2.0 s. A team-and-model filter took 1.3 s with rollup reads (3.5 s p95) and 645 ms in ClickHouse.
- **Request logs:** PostgreSQL was faster for index-friendly pages: the first page, a team's errors and offset 5,000 took 1–5 ms, against 12–33 ms in ClickHouse at 1M and 66–98 ms at 10M. The sparse 90-day filter (status 502, one provider, one operation) went the other way: 31 ms against 5.5 ms at 1M, and 242 ms against 27 ms at 10M. Trace and session pages depended on PostgreSQL's plan for the sampled ID: 154 and 236 ms at 1M but under 1 ms at 10M, against 4–5 ms in ClickHouse at both.
- **Same answers:** every ClickHouse answer equalled PostgreSQL's wherever PostgreSQL answered: 12 endpoints at 1M and 7 at 10M. PostgreSQL timed out on the others, which T019.001 compared engine to engine.
- **Inference path:**
  - Copy on and off cost the same per request: gateway CPU was 0.640 ms in both, and PostgreSQL CPU 0.983 against 0.995 ms.
  - The copy added about 21 MiB to the gateway's peak RSS (84 against 63 MiB) and one PostgreSQL connection of its own. There were no errors.
  - Throughput medians were 979 (copy on) and 1,153 (copy off) requests/s, but the ranges overlap (926–1,337 and 1,111–1,221) and CPU per request did not change. On this host that difference cannot be told from noise.
- **Copy lag:** 1.1 s p50, 2.0 s p95 and 2.2 s max under that load, within the 2 s copy interval. After a 60 s ClickHouse outage the copy was current again 2.4 s after the resume. Inference kept running with no errors, at 827 requests/s during the pause against 1,037 before. Reads at the start of the outage waited on ClickHouse, and at least one answered 503 after 5 s before the replica fell back to PostgreSQL.
- **Initial copy:** 6.1 s for 1M events and 69 s for 10M through the gateway, about 144,000–163,000 events/s with the default batch.
- **Resources at 10M:**
  - **Disk:** ClickHouse used 0.65 GiB against 7.2 GiB for the PostgreSQL table and indexes. ClickHouse adds to PostgreSQL; it does not replace it.
  - **At rest, copy current:** ClickHouse held 3.5 GiB of memory (page cache included) and used 11% of a core for its merges and the copy's passes. PostgreSQL held 3.1 GiB and used under 1%.
  - **Endpoint runs with reads on PostgreSQL:** PostgreSQL used 383 CPU-seconds in 270 s, at a 5.7 GiB peak.
  - **Endpoint runs with reads on ClickHouse:** ClickHouse used 166 CPU-seconds in 47 s, nearly all of its 4 cores, at a 4.3 GiB peak. PostgreSQL was almost idle.

### When to choose which

- **Up to about 1M events per 90 days (about 11,000 a day):** stay on PostgreSQL and turn on rollup reads. Every Usage view answered within 1.5 s, the end-user and tag rankings within 2.1 s and the tag filter in 3.9 s. ClickHouse brings p95 over the whole window and sub-200 ms views, at the price of one more service.
- **Between 1M and 10M events per 90 days:** first turn on rollup reads. In this range, the 90-day views and the end-user and tag rankings and filters reach PostgreSQL's 5 s deadline. Choose ClickHouse for analytics (`analytics_store_usage`) when they still fail.
- **From about 10M events per 90 days (about 110,000 a day):** choose ClickHouse for analytics. PostgreSQL answers only the 7-day view, in 3.6 s, and with rollups the 30-day one. ClickHouse answered every view, ranking and filter in at most 2.1 s.
- **Request logs (`analytics_store_request_logs`):** keep them on PostgreSQL unless sparse filters over long windows are what is slow. PostgreSQL answers index-friendly pages and lookups in a few milliseconds, faster than ClickHouse at every volume measured. The rare-filter page took 242 ms in PostgreSQL at 10M, and 12.5 s at 50M in T019.001.
- **What ClickHouse costs to operate:**
  - one more service to run, back up and upgrade, from an image of about 1 GB;
  - at 10M events, about 3.5 GiB of memory, a tenth of a core at rest and disk of about 9% of PostgreSQL's events table;
  - one more PostgreSQL connection per replica, and about 21 MiB more gateway memory;
  - answers about 2 s behind PostgreSQL; reads fall back to PostgreSQL past `copy.max_lag` (5 min);
  - during an outage, the first reads on each replica can wait up to the dial timeout and answer 503 before falling back.

<!-- generated by scripts/bench-gateway-store.py from gateway-store.json: do not edit below -->

Measured 2026-11-16 at `dcefb695+c4c4d1a88884` (commit, and a hash of uncommitted changes to the measured code) on Apple M4 Pro, 12 CPUs; engines `--cpus 4 --memory 6g` each; 7 runs per endpoint after one warm-up (p95 of seven runs is the slowest). A cell marked 503 mixes answers and 5 s timeouts in its percentiles; a ClickHouse cell that names another store was answered, in some runs, by it.

### 1,000,000 events, through the gateway

| Endpoint | PostgreSQL p50 / p95 ms | PostgreSQL, rollup reads p50 / p95 ms | ClickHouse p50 / p95 ms | Same answer |
|---|---:|---:|---:|---|
| `view_7d` | 301 / 389 | 318 / 397 | 57.6 / 67.7 | equal |
| `view_30d` | 1,686 / 1,690 | 392 / 546 | 124 / 131 | equal |
| `view_90d` | 4,633 / 5,002 (200, 503) | 1,465 / 1,480 | 166 / 175 | equal |
| `end_user_and_tag_ranking_30d` | 1,819 / 1,879 | 702 / 735 | 131 / 139 | equal |
| `end_user_and_tag_ranking_90d` | 5,005 / 5,006 (503) | 2,018 / 2,132 | 188 / 197 | postgresql did not answer |
| `team_model_90d` | 468 / 1,563 | 479 / 490 | 139 / 174 | equal |
| `tag_env_90d` | 3,927 / 3,933 | 3,893 / 3,954 | 310 / 319 | equal |
| `log_first_page_90d` | 1.39 / 1.76 | 1.08 / 1.33 | 29.1 / 31.1 | equal |
| `log_team_errors_30d` | 1.58 / 1.97 | 1.15 / 1.21 | 11.9 / 13.6 | equal |
| `log_rare_filter_90d` | 31.1 / 35.7 | 38.3 / 45.4 | 5.54 / 6.94 | equal |
| `log_offset_5000_90d` | 3.30 / 3.56 | 4.29 / 4.37 | 28.7 / 32.3 | equal |
| `trace_90d` | 154 / 159 | 153 / 155 | 4.52 / 4.99 | equal |
| `request_lookup` | 0.75 / 0.82 | 0.72 / 1.15 | 0.99 / 1.38 (PostgreSQL) | postgresql in both modes |
| `session_page_90d` | 236 / 245 | 234 / 239 | 4.15 / 4.67 | equal |
| `session_summary_90d` | 0.78 / 0.86 | 1.27 / 1.54 | 1.14 / 1.32 (PostgreSQL) | postgresql in both modes |

| Resources | PostgreSQL | ClickHouse |
|---|---:|---:|
| Disk: events table and indexes / copied table | 0.72 GiB (rollups 0.04 GiB) | 0.07 GiB |
| At rest, copy current (10 s): CPU / memory (cgroup, page cache included) | 2.9% / 1,659 MiB | 10.6% / 1,259 MiB |
| During the endpoint runs with reads on PostgreSQL as shipped (149 s): CPU / peak memory | 150.4 s / 1,961 MiB | 6.7 s / 2,066 MiB |
| During the endpoint runs with reads on PostgreSQL, rollup reads (79 s): CPU / peak memory | 80.5 s / 1,892 MiB | 3.6 s / 1,388 MiB |
| During the endpoint runs with reads on ClickHouse (10 s): CPU / peak memory | 0.2 s / 1,688 MiB | 23.6 s / 2,150 MiB |
| Initial copy through the gateway (default batch 5,000) | — | 6.1 s (162,962 events/s) |

### Inference path with the copy on and off (1,000,000 events stored, instant upstream, c=32)

3 alternating rounds of 50,000 requests per condition; median (min–max) of the rounds.

| | Copy off | Copy on |
|---|---:|---:|
| Requests per second | 1,153 (1,111–1,221) | 979 (926–1,337) |
| Latency p50 ms | 21.5 (21.4–21.6) | 22.6 (19.6–22.8) |
| Latency p99 ms | 197 (93.5–232) | 241 (63.4–271) |
| Gateway CPU per request | 0.640 ms (0.639 ms–0.644 ms) | 0.640 ms (0.631 ms–0.652 ms) |
| Gateway peak RSS | 63 MiB (62 MiB–63 MiB) | 84 MiB (84 MiB–93 MiB) |
| PostgreSQL CPU per request | 0.995 ms (0.971 ms–1.037 ms) | 0.983 ms (0.898 ms–1.062 ms) |
| ClickHouse CPU in the round | 3.1 s (3.1 s–3.2 s) | 4.3 s (3.6 s–5.2 s) |
| Errors | 0 | 0 |
| Copy lag during the rounds p50 / p95 / max | — | 1.1 / 2.0 / 2.2 s (395 samples, one every 0.37 s) |
| Copy current again after a round | — | 1.5 s (1.5 s–1.6 s) |

**ClickHouse outage** (load at c=8 throughout; ClickHouse paused for 60 s, then resumed): inference ran at 1,037 requests/s before the pause and 827 during it, with 0 errors in all. The copy was current again 2.4 s after the resume; the lag peaked at 64 s and the backlog at 52,768 events. During the pause, 16 reads of the Usage view and a log page answered with status 200, 503 from PostgreSQL (unavailable), the slowest in 5,002 ms; while the copy caught up, 2 reads answered with status 200 from PostgreSQL (unavailable).

### 10,000,000 events, through the gateway

| Endpoint | PostgreSQL p50 / p95 ms | PostgreSQL, rollup reads p50 / p95 ms | ClickHouse p50 / p95 ms | Same answer |
|---|---:|---:|---:|---|
| `view_7d` | 3,599 / 3,633 | 3,534 / 3,627 | 148 / 159 | equal |
| `view_30d` | 5,005 / 5,006 (503) | 2,758 / 3,077 | 425 / 485 | postgresql did not answer |
| `view_90d` | 5,006 / 5,010 (503) | 5,005 / 5,007 (503) | 848 / 867 | postgresql did not answer |
| `end_user_and_tag_ranking_30d` | 5,005 / 5,009 (503) | 4,884 / 4,972 | 426 / 440 | postgresql did not answer |
| `end_user_and_tag_ranking_90d` | 5,006 / 5,007 (503) | 5,004 / 5,009 (503) | 994 / 1,017 | postgresql did not answer |
| `team_model_90d` | 5,006 / 5,011 (503) | 1,290 / 3,539 | 645 / 664 | postgresql did not answer |
| `tag_env_90d` | 5,005 / 5,007 (503) | 5,005 / 5,006 (503) | 2,027 / 2,082 | postgresql did not answer |
| `log_first_page_90d` | 1.98 / 4.51 | 1.45 / 2.40 | 82.9 / 98.4 | equal |
| `log_team_errors_30d` | 1.20 / 1.60 | 1.61 / 1.75 | 66.3 / 71.8 | equal |
| `log_rare_filter_90d` | 242 / 268 | 238 / 265 | 27.1 / 30.6 | equal |
| `log_offset_5000_90d` | 2.97 / 3.44 | 3.30 / 3.69 | 81.8 / 92.7 | equal |
| `trace_90d` | 0.67 / 0.90 | 0.76 / 1.07 | 4.69 / 5.26 | equal |
| `request_lookup` | 0.61 / 0.67 | 0.54 / 0.57 | 0.69 / 0.77 (PostgreSQL) | postgresql in both modes |
| `session_page_90d` | 0.61 / 0.63 | 0.60 / 0.67 | 4.31 / 4.40 | equal |
| `session_summary_90d` | 0.71 / 0.83 | 0.70 / 0.76 | 1.01 / 1.63 (PostgreSQL) | postgresql in both modes |

| Resources | PostgreSQL | ClickHouse |
|---|---:|---:|
| Disk: events table and indexes / copied table | 7.20 GiB (rollups 0.10 GiB) | 0.65 GiB |
| At rest, copy current (10 s): CPU / memory (cgroup, page cache included) | 0.8% / 3,112 MiB | 10.9% / 3,487 MiB |
| During the endpoint runs with reads on PostgreSQL as shipped (270 s): CPU / peak memory | 383.1 s / 5,680 MiB | 14.1 s / 1,957 MiB |
| During the endpoint runs with reads on PostgreSQL, rollup reads (228 s): CPU / peak memory | 310.3 s / 5,691 MiB | 13.0 s / 1,940 MiB |
| During the endpoint runs with reads on ClickHouse (47 s): CPU / peak memory | 0.4 s / 3,112 MiB | 166.3 s / 4,310 MiB |
| Initial copy through the gateway (default batch 5,000) | — | 69.4 s (144,050 events/s) |

<!-- end of gateway tables -->

## Reproduce

```bash
go build -o "$TMPDIR/gateway" ./cmd/gateway
python3 scripts/bench-analytics-store.py setup --gateway "$TMPDIR/gateway"
python3 scripts/bench-analytics-store.py run --volumes 1000000,10000000,50000000 --out docs/benchmarks/analytics-store.json
python3 scripts/bench-analytics-store.py teardown
python3 scripts/bench-analytics-store.py render docs/benchmarks/analytics-store.json --page docs/benchmarks/analytics-store.md
```

Through the gateway (T019.006); the harness records its SHA-256, the commit and a hash of uncommitted changes to the measured code, the images, limits and settings:

```bash
npm --prefix web ci && npm --prefix web run build
python3 scripts/bench-gateway-store.py setup
python3 scripts/bench-gateway-store.py run --volumes 1000000,10000000 --out docs/benchmarks/gateway-store.json
python3 scripts/bench-gateway-store.py teardown
python3 scripts/bench-gateway-store.py render docs/benchmarks/gateway-store.json --page docs/benchmarks/analytics-store.md
```

For both harnesses, `setup` creates the labelled network, volumes and containers with the exact images, limits and settings above, and migrates the database with the gateway binary. `teardown` removes them and fails if any labelled resource remains. The T019.001 result records the harness's SHA-256 and each container's image, command and limits. The gate runs both renders with `--check`, so the tables cannot drift from the recorded JSON.
