Why it matters

Moving statistics enable real-time monitoring. Understanding shapes streaming.

Advertisement

The architecture

Two heaps: max-heap for lower half, min-heap for upper.

Balance sizes.

Median = tops.

Two-heap medianMax-heaplower halfMin-heapupper halfMediantopsFor arbitrary percentiles, use t-digest or DDSketch sketches
Two-heap.
Advertisement

How it works end to end

Insert: to appropriate heap.

Rebalance sizes.

Delete on window slide: lazy deletion via ordered map.

Sketches (t-digest) for percentiles + memory.