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

Relationships

#856 Epic #847 · Unit 4: Stream confirmed grants into ClickHouse score_grants (ReplacingMergeTree)

Opened by keeb · 6/27/2026

Part of epic #847. Unit 4 of 6. Prerequisites: #853 (ClickHouse foundation) and #855 (grants are the authoritative source).

Problem

The ledger lives in Mongo; ClickHouse must own the projections (Unit 5). Grants must reach CH exactly once. ClickHouse cannot provide insert-time uniqueness or read-your-write — it dedups only async at merge — so we stream after the Mongo grant is confirmed-new.

Scope

  1. CH score_grants table, ReplacingMergeTree(grantId) as belt-and-suspenders dedup.
  2. Stream each confirmed-new Mongo grant into CH score_grants (stream-after-confirm so CH never sees a duplicate in the normal path).
  3. Reuse the existing near-real-time consumer pattern (services/telemetry/lib/consumers/clickhouse.ts); preserve trace context across the hop per the observability rules in CLAUDE.md (QueueCollection _otel linkage / serviceClient).

Out of scope

  • Projections / materialized views / app read path (Unit 5).

Acceptance

  • Every Mongo grant appears exactly once in CH score_grants.
  • A replayed/duplicate grantId still yields a single effective row (ReplacingMergeTree collapses it).
  • No projection or read-path changes yet — leaderboards still read the legacy path.

Tests

  • tests/integration/ — 1:1 Mongo-grant → CH-row; duplicate grantId collapses to one.

Files

  • infrastructure/clickhouse/init/*.sql (score_grants table)
  • services/telemetry/lib/consumers/clickhouse.ts or a sibling grant consumer
02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED

Open

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

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.