Skip to content

lore-0049: rewrite overview to match ADR 0007 (Hetzner CH)#26

Open
karczuRF wants to merge 2 commits into
developfrom
lore-0049/overview-rewrite-adr-0007
Open

lore-0049: rewrite overview to match ADR 0007 (Hetzner CH)#26
karczuRF wants to merge 2 commits into
developfrom
lore-0049/overview-rewrite-adr-0007

Conversation

@karczuRF
Copy link
Copy Markdown
Collaborator

Summary

Rewrite docs/prices-api-general-overview.md to match ADR 0007 (live data sink on shared Hetzner ClickHouse), accepted in PR #25. Sixteen sections touched plus a new Revision History row.

Note on stacking. This branch is stacked on top of lore-0045/close-be-agreement so the ADR 0007 accepted state is in the working base. Until #25 merges, this PR's diff will appear to include both sets of changes. GitHub will rebase the diff once #25 lands.

Section-by-section

Section Change
Revision History New 2026-05-20 row referencing ADR 0007 + tasks 0045 / 0046 / 0049
§0 Deployment Hetzner CH data plane added; no-VPC framing
§1.1 API Layer diagram ClickHouse via HTTPS-mTLS replaces RDS
§1.2 Data Ingestion diagram SNS fan-out + CH + MV chain replace direct-S3 + RDS + Rollup Lambda
§2.1 Components RDS / NAT / OHLCV Rollup moved to "no longer in budget" list; mTLS material added to Secrets Manager line
§2.3 Shared with BE Hetzner CH + SNS fan-out + mTLS CA added; VPC + NAT moved to "no longer shared because not needed"
§3 Schema Full rewrite — PostgreSQL → ClickHouse ReplacingMergeTree(version) per-source, per-granularity tables, MV chain, monthly partitions, ALTER TABLE DROP PARTITION cleanup
§4.5 /backfill/status Endpoint contract unchanged; underlying table notes ClickHouse
§5.2 Ledger Processor UPSERT → ReplacingMergeTree INSERT; mTLS write path; warm-connection reuse
§5.3 / §5.4 OHLCV Rollup row + EventBridge rule removed (replaced by CH MV chain)
§5.5 VWAP layering Preserved unchanged (added by task 0048)
§5.6 Backfill Cloud-push targets shift RDS → Hetzner CH; local backfill itself unchanged
§6 Performance RDS sizing ladder removed; sidecar-CH fallback (ADR 0007 Alt 3) documented
§7 Security mTLS section added (per-env certs, rotation, revocation)
§8 Tech Stack sqlxclickhouse crate; PostgreSQL 16 → ClickHouse + Caddy
§9 Tranche 1 No RDS / VPC / NAT in CDK synth; SNS subscription wiring
§10 Cost $12/mo RDS removed; ~$1-2/env/mo Hetzner CH cost-share added (basis: task 0046 empirical ~0.45 GB/yr)
§11 Sharing Hetzner CH + mTLS CA added to §11.1; agreement record linked from §11.1/§11.2/§11.4

Verification

Final grep on the doc confirms:

  • No sqlx or PostgreSQL 16 outside the historical Revision History
  • No db.t4g.* / db.m6g.* / db.r6g.* / RDS Proxy / Multi-AZ / RDS read replica in live-state text
  • No ohlcv-rollup / "OHLCV Rollup Lambda" except in explicit "removed" callouts
  • No NAT Gateway / VPC in live-state text except in "no longer needed" callouts
  • RDS mentions are confined to: Revision History rows, explicit "removed" / "no longer" callouts, and the §2.3 paragraph documenting obsolete table rows

Net change: +788 / -384 lines.

Test plan

  • Read §3 schema DDL in a viewer — confirm engines, sort keys, MV chain example all look correct
  • Confirm §10 cost table matches task 0046's empirical numbers (~0.45 GB/yr, ~$1-2/env/mo cost-share)
  • Confirm §11.1 "Monthly saving" total recomputes correctly (~$49/mo)
  • Spot-check Mermaid / ASCII diagrams in §1.1 and §1.2 render cleanly
  • Confirm docs/prices-api-general-overview.md references in other lore tasks (0011/0038/0039/0040) still resolve

Follow-ups (out of scope)

  • docs/database-schema/clickhouse-prod-schema.sql — the full schema reference referenced from §3.2 still needs to be written
  • OpenAPI spec — Tranche 3 deliverable
  • Wiki sweep for stale RDS / sqlx mentions in lore/3-wiki/

🤖 Generated with Claude Code

Sixteen sections touched (§0, §1.1, §1.2, §2.1, §2.3, §3, §4.5,
§5.2–§5.4, §5.6, §6, §7, §8, §9, §10, §11) plus a new Revision
History row. The live data sink description flips from Prices-
owned RDS PostgreSQL to BE's shared Hetzner ClickHouse cluster
(separate `prices` database) per ADR 0007 (accepted in PR #25).

Key shape changes:
- §1.1 / §1.2 diagrams: ClickHouse + SNS fan-out replace RDS +
  direct S3 → Lambda.
- §2.1: RDS, NAT Gateway, OHLCV Rollup Lambda moved into a
  "no longer in the budget" sub-list; Secrets Manager line updated
  to mention per-env mTLS material.
- §2.3: Hetzner CH data plane and mTLS CA added as shared
  components; VPC + NAT Gateway moved to a "no longer shared
  because not needed" callout.
- §3: schema rewritten from PostgreSQL native range partitioning
  to ClickHouse — `ReplacingMergeTree(version)` per-source rows on
  per-granularity tables (`price_ohlcv_1m`/`_15m`/.../`_1M`) with
  a materialised-view rollup chain that eliminates the OHLCV
  Rollup Lambda. Backfill progress on `ReplacingMergeTree(updated_at)`.
  Cleanup via `ALTER TABLE … DROP PARTITION`.
- §5.2: UPSERT → ReplacingMergeTree INSERT (version-keyed
  idempotency); HTTPS-mTLS to Caddy:443; warm connection reuse
  to amortise the ~80-130 ms cross-cloud RTT.
- §5.3 / §5.4: OHLCV Rollup row + EventBridge rule removed.
- §6: RDS sizing/scaling ladder removed; replaced with a short
  CH-on-Hetzner sizing note pointing to the sidecar-CH fallback
  (ADR 0007 Alternative 3) if task 0047 returns RED.
- §7: mTLS section added (per-env certs, 1-year rotation, CA
  revocation, NotAfter alarm).
- §8: sqlx → `clickhouse` Rust crate; Hetzner CH + Caddy in the
  stack table.
- §10: $12/mo RDS line removed; ~$1-2/env/mo Hetzner CH cost-share
  added per task 0046's empirical ~0.45 GB/yr footprint. Steady-
  state per env: ~$108/mo. The RDS escalation ladder
  (db.r6g.large + Multi-AZ + read replica + Proxy) eliminated.
- §11: sharing table refreshed — Hetzner CH and mTLS CA added;
  agreement record from task 0045 referenced in §11.1, §11.2,
  and §11.4 risk table.

Preserved unchanged:
- §5.5 L1/L2/L3 VWAP layering callout (added by task 0048).
- Local backfill sections (Stream 1 ADR 0001, Stream 2 ADR 0005)
  — only the cloud-push targets shift RDS → Hetzner CH `prices.*`.

Final grep confirms no live-state RDS / NAT Gateway / OHLCV
Rollup / sqlx references remain in the document body — only
historical context in the Revision History and explicit "removed"
callouts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@karczuRF karczuRF force-pushed the lore-0049/overview-rewrite-adr-0007 branch from d1ee0e5 to 20bb744 Compare May 20, 2026 20:19
Companion to the main overview rewrite (commit 20bb744). Brings
docs/database-schema/ in line with ADR 0007 (live data sink on
shared Hetzner ClickHouse):

- amm-trades-schema.md: added a clear SUPERSEDED banner pointing at
  ADR 0001, ADR 0007, and BE ADRs 0044/0045. The pre-ADR-0001
  design (custom AMM trades table on BE's RDS) is no longer
  pursued; the file is retained for historical context only.

- database-schema-overview.md (1540 → 1906 lines, +366 net):
  full rewrite across all 13 sections + both Appendices.

  - Revision History row added.
  - §1.1 / §1.2 diagrams: ClickHouse + SNS fan-out + mTLS Caddy
    edge replace RDS + direct S3.
  - §2 Tech Stack: PostgreSQL 16 → ClickHouse on Hetzner;
    sqlx → `clickhouse` Rust crate; MV-chain rollups; mTLS
    material in Secrets Manager.
  - §3 Schema: full rewrite to ClickHouse DDL —
    `ReplacingMergeTree(version)` per-source rows on
    per-granularity `price_ohlcv_*` tables, MV chain sketch
    for the 1m → 15m → ... → 1M rollup, `prices.assets` /
    `current_prices` / `oracle_prices` / `backfill_progress`
    on appropriate engines.
  - §4 Retention: `ALTER TABLE ... DROP PARTITION` per
    per-granularity table (no row DELETEs).
  - §5 reframed as "Sort Keys & Query Patterns" — CH sort key
    semantics, projections-not-B-tree-indexes.
  - §6 Workers: OHLCV Rollup Lambda row removed; MV chain noted
    as the replacement; `ohlcv-rollup` EventBridge rule gone.
  - §7 Backfill: both streams' diagrams + metric tables reflect
    local CLIs + Hetzner CH push targets; `task_healthy` /
    `last_heartbeat` swapped for `last_push_at` everywhere;
    §7.6 example response uses the new field shape.
  - §8 reframed as "Sizing, Performance, Scaling (Hetzner
    ClickHouse)" — RDS escalation ladder removed, sidecar-CH
    fallback documented, cost lines updated to ~$1-2/env/mo
    cost-share per task 0046.
  - §9 Security: mTLS sub-bullets (per-env certs, 1-year
    rotation, CA revocation, NotAfter alarm); no-VPC framing;
    Borg RPO trade-off.
  - §10 Cross-Service Dependency: rewritten around Hetzner
    shared tenancy (ADR 0007); mermaid block shows the
    co-tenancy boundary.
  - §11 What Is Not Shared: RDS instance row replaced with
    `prices.*` schema + onboarding portal rows.
  - §12 Tranche-1 acceptance: flipped to ClickHouse / no-VPC /
    SNS / mTLS / push-cadence.
  - §13 Quick Reference: engine + sort-key + partition columns
    per per-granularity table.
  - Appendix A (ER diagram): full rewrite to CH types, engines,
    MV-chain edges, no SQL FKs.
  - Appendix B (full system diagram): full rewrite — SNS bucket
    fan-out, mTLS edge, Hetzner box with shared CH (default.* +
    prices.*), workstation backfill subgraph (BE backfill-runner,
    local CH, local Postgres, cloud-push tools), MV chain dotted
    edges, push-freshness alarm.

clickhouse-prod-schema.sql left as-is (BE's `default.*`
production reference, not prices-api's schema).

Task 0049 closed (expanded scope; reopened earlier today as
this work was identified). Final grep confirms no live-state
RDS / sqlx / PostgreSQL 16 / OHLCV Rollup / ECS Fargate
references remain in current-state text.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant