Why architecture matters here

Reservoir sampling fails on bad RNG, wrong weighted math, or naive parallel merge. Architecture matters because guarantees depend on details.

Advertisement

The architecture: every piece explained

The top strip is basics. Stream. Reservoir size k. Algorithm R — coin flip per item. Vitter — geometric jump.

The middle row is variants. Weighted (A-Res) — priority. Distributed — per-shard reservoirs merged. Streaming APIs — top-K queries. Guarantees uniform or weighted.

The lower rows are practice. Use cases log sampling + trace. Metrics variance. Ops RNG + audit + composition.

Reservoir sampling — Algorithm R + Vitter + weighted + paralleluniform samples from streams of unknown sizeStreamunknown lengthReservoir size ktarget sampleAlgorithm Rcoin flip per itemVitter A/L/Zfaster O(k log n)Weighted (A-Res)priorityDistributedper-shard + mergeStreaming APIstop-K queriesGuaranteesuniform / weightedUse caseslog sampling / traceMetricssample size + varianceOps — RNG + audit + compositionweightshardexposeverifyapplymeasuremeasureoperateoperate
Reservoir sampling variants and distributed merge.
Advertisement

End-to-end flow

End-to-end: log pipeline produces 1M events/min. Sample 1000 uniformly. Algorithm R per shard; merge preserves uniformity. Weighted variant used for prioritized sampling of errors.