Sampling Away Your Outage: Honest Telemetry at the Edge
Uniform 1-in-100 head sampling is wonderful for estimating overall request volume and terrible for the moment an error rate climbs from 0.1% to 1.5%. Worse, dividing two independently sampled estimators quietly invents impossible percentages.
When an analytics pipeline samples writes at ingest, low-frequency events disappear first. If pageviews are sampled at 1 in 7 and conversion events are sampled on a separate path, a naive ratio between them can read 158% on real traffic. Clamping that ratio to 100% doesn't fix the math — it only deletes the evidence that you were guessing.
Two sinks beat one compromised table
The cleanest architecture separates shape telemetry from ledger events at ingest. High-volume noise (pageviews, hover signals, fast 200 responses) goes into a cheap columnar analytics sink. Anything you would show on an invoice or use as a headline denominator goes through a durable queue into a transactional log.
// Separate high-volume shape metrics from exact auditable rows
env.EVENTS.writeDataPoint({ blobs: [event.type, site, page, '', posture], doubles: [dt, holdout, 1] });
if (AUDITABLE_TYPES.includes(event.type)) {
const id = await sha256Hex(`${site}\0${event.sid}\0${page}\0${event.type}`);
billable.push({ id, site_id: site, page, event_type: event.type, posture, fulfillment_by, fulfillment_ref, ts });
}
Surface the sampling interval in the UI
Never render an estimated count in the exact same typographic weight as
an exact ledger count. Prefixing estimates with ≈ and
returning the actual sampling interval lets operators tell a noisy
estimate from a broken instrumentation pipeline in three seconds.
Tail-based retention applies the exact same philosophy to traces: keep 100% of slow spans and 5xx failures, sample the routine 12 ms health checks, and never pretend a 1% sample is an audit log.