Skip to main content
← Back to list
01Issue
FeatureOpenSwamp CLI
AssigneesNone

Relationships

#857 Epic #847 · Unit 5: ClickHouse materialized-view projections + atomic leaderboard read-flip + delete Mongo OLAP

Opened by keeb · 6/27/2026

Part of epic #847. Unit 5 of 6 — the "ship together" cutover. Prerequisite: #856 (grants in ClickHouse). This is the only unit where the ledger and the CH projection layer go live as the user-facing path together; per the epic's acceptance, neither half ships to main as the user-facing scoring path without the other.

Scope

  1. Build CH materialized views over score_grants: all-time / window (sumIf(amount, granted_at >= window)) / streak / per-category / tier-distribution leaderboards, plus the metrics dashboards.
  2. Add the app read path: leaderboard queries read CH MVs instead of mongo-leaderboard-query.findTopByWindow.
  3. Atomic flip of leaderboard / window / streak / category / tier reads from Mongo to ClickHouse.
  4. Delete the hand-rolled Mongo OLAP primitives now that nothing reads them:
    • event_rollups + 15min/hour/day bucket math (services/telemetry/lib/consumers/metrics.ts)
    • metric_snapshots_daily + composite-$max window diff (lib/infrastructure/mongo-leaderboard-query.ts:245-375)
    • the username_metrics 3-path projection (services/telemetry/lib/consumers/stats.ts)
    • the unique_ids $addToSet / $setUnion read-time distinct counts
  5. Stays in Mongo (the boundary): milestone counters (arrival-order, transactional) and exclusive-badge claims (unique partial index, one-holder-ever) — do NOT move these.

Acceptance

  • Leaderboard / window / streak / category / tier / metric projections are served from CH materialized views.
  • The deleted Mongo collections have no remaining readers (CI grep).
  • Old-vs-new leaderboard parity holds on a seeded dataset.
  • Window queries collapse to sumIf and match the prior point-in-time gains (the non-monotonic composite-$max window function is gone).

Tests

  • tests/integration/ — old vs new leaderboard / window parity on seeded data.
  • CI grep — event_rollups / metric_snapshots_daily / composite-$max window-diff unreferenced.

Files

  • infrastructure/clickhouse/init/*.sql (materialized views)
  • lib/infrastructure/mongo-leaderboard-query.ts (delete window-diff; new CH read path)
  • services/telemetry/lib/consumers/metrics.ts, stats.ts (delete OLAP)
  • leaderboard read path in lib/app/ + routes/
02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED

Open

6/27/2026, 3:34:25 AM

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.