Skip to main content
ARCHOS 525 BLUEPRINT · /d/dgm_code-cardinality-and-sampling-streams

Cardinality Estimation & Stream Sampling (HyperLogLog & Reservoir)

6 COMPONENTS · 6 FLOWS · UPDATED 2026-11-24
GITHUB README / PR PREVIEW CARD
[![Cardinality Estimation & Stream Sampling (HyperLogLog & Reservoir) — ArchOS Architecture](https://archos.sageideas.dev/d/dgm_code-cardinality-and-sampling-streams/opengraph-image)](https://archos.sageideas.dev/d/dgm_code-cardinality-and-sampling-streams)

*Interactive architecture diagram powered by [ArchOS Studio](https://archos.sageideas.dev/d/dgm_code-cardinality-and-sampling-streams)*
NOTION / DOCS / CONFLUENCE EMBED
<iframe src="https://archos.sageideas.dev/embed/dgm_code-cardinality-and-sampling-streams" width="100%" height="580" style="border:1px solid rgba(240,236,225,0.14);border-radius:6px;" loading="lazy" title="Cardinality Estimation & Stream Sampling (HyperLogLog & Reservoir) — Interactive in ArchOS"></iframe>
PORTABLE MERMAID SPEC (GITHUB / NOTION / RFC)
flowchart LR
  client_0["Click / Telemetry Stream"]
  n1_1["64-Bit Uniform Hash"]
  n2a_2[("HyperLogLog Registers")]
  n2b_3[("Reservoir Sampler")]
  n3_4[("Mergeable Rollups")]
  downstream_5["Downstream & OTel"]
  client_0 -->|"1. Hash item · xxHash"| n1_1
  n1_1 -->|"2a. Max rho · HLL"| n2a_2
  n1_1 -->|"2b. Keep K/i · Reservoi"| n2b_3
  n2a_2 -->|"3a. Merge max · OLAP"| n3_4
  n2b_3 -->|"3b. Merge · RAM"| n3_4
  n3_4 -.->|"4. Emit / · OTLP/API"| downstream_5

COMPONENT STACK (6)

  • Click / Telemetry StreamSTATELESS
    Billions of user_ids
  • 64-Bit Uniform HashSTATELESS
    Leading-zero geometric run
  • HyperLogLog RegistersSTATEFUL
    16,384 6-bit regs
  • Reservoir SamplerSTATEFUL
    Uniform K-sample in O RAM
  • Mergeable RollupsSTATEFUL
    Union HLL across time/shards
  • Downstream & OTelSTATELESS
    Consumers, metrics & SLOs

REQUEST & DATA FLOW (6)

  1. Click / Telemetry Stream → 64-Bit Uniform Hash (Hash item)[xxHash]
  2. 64-Bit Uniform Hash → HyperLogLog Registers (Max rho)[HLL]
  3. 64-Bit Uniform Hash → Reservoir Sampler (Keep K/i)[Reservoi]
  4. HyperLogLog Registers → Mergeable Rollups (Merge max)[OLAP]
  5. Reservoir Sampler → Mergeable Rollups (Merge)[RAM]
  6. Mergeable Rollups → Downstream & OTel (Emit /)[OTLP/API]
Configure NGINX / Postgres / K8s →60-Sec L4–L7 Diagnostic →