TL;DR
This paper introduces ReqSketch, a novel randomized streaming algorithm that estimates quantiles with relative error guarantees rather than standard additive error. By employing a clever, derandomized compaction schedule that protects low-ranked items, it achieves a state-of-the-art space complexity of $O(\frac{1}{\varepsilon} \log^{1.5}(\varepsilon n))$ items. The algorithm requires no prior knowledge of the stream length and is fully mergeable, making it ideal for distributed computing environments.
What Problem Does This Paper Address?
Calculating quantiles (like the median or the 99th percentile) over massive, fast-moving data streams is a foundational task in data science. Most existing streaming algorithms, such as the widely used KLL sketch, provide additive error guarantees ($\pm \varepsilon n$). While this works well for the bulk of a distribution, it fails catastrophically at the tails.
For example, if you are monitoring network latency and care about the difference between the 99.5th and 99.9th percentiles, an additive error bound might completely blur the distinction if the total number of elements $n$ is huge. To accurately diagnose anomalies in long-tailed distributions, we need relative error (or multiplicative error) guarantees, ensuring that the estimate is accurate within a factor of $(1 \pm \varepsilon) \cdot \text{Rank}$.
Prior algorithms providing relative error guarantees were either space-inefficient—requiring $O(\frac{1}{\varepsilon^2} \log(\varepsilon^2 n))$ space—or placed heavy restrictions on the data, such as requiring a bounded universe or knowing the stream length in advance.
Methods
The authors build upon the hierarchical buffer structure popularized by the KLL sketch but introduce a new building block: the relative-compactor.
Instead of compacting an entire buffer when it fills up, a relative-compactor always protects the smallest items to maintain high relative accuracy for low ranks. The buffer is divided into sections of size $k$. When the buffer is full, the algorithm sorts the largest $L$ items, discards every other item (simulating a coin flip for data reduction), and retains the rest.
The core innovation lies in how $L$ (the number of items to compact) is chosen. The authors design a deterministic compaction schedule based on a derandomized exponential distribution. By looking at the number of trailing ones in the binary representation of the compaction count ($C$), the algorithm decides exactly how many sections of the buffer to involve in the compaction.
To make the algorithm work with unknown stream lengths, it dynamically "closes out" summaries and initializes larger ones as the stream grows. Furthermore, to support distributed architectures, the states of two compactors can be merged simply by performing a bitwise OR operation on their compaction counters ($C$).
Datasets
Not discussed in the paper. (This is a theoretical paper focused on proving algorithmic upper and lower bounds; however, the authors note that a production-quality implementation has been integrated into the Apache DataSketches library).
Key Insights and Ideas
- Rank-Proportional Protection: To achieve relative error, a sketch must provide exact ranks for the lowest $1/\varepsilon$ items, and sample higher ranks with an exponentially decreasing density.
- Bitwise State Merging: The realization that a bitwise OR operation on binary compaction counters perfectly preserves the structural guarantees of a derandomized exponential distribution across independent data streams. This is what allows
ReqSketchto be fully mergeable without losing accuracy. - Sub-Gaussian Error Cancellation: Even though errors are introduced at multiple levels of the compactor hierarchy, the random choices (compacting odd vs. even indexed items) behave as zero-mean sub-Gaussian variables, leading to massive error cancellation that keeps the variance tightly bounded.
Key Results
- Space Complexity: For a constant failure probability $\delta$,
ReqSketchstores $O(\frac{1}{\varepsilon} \log^{1.5}(\varepsilon n))$ items. This is strictly more space-efficient than any deterministic comparison-based algorithm and sits within a tiny $O(\sqrt{\log(\varepsilon n)})$ factor of the theoretical randomized lower bound. - Speed: The amortized update time per item is incredibly fast at $O(\log(\frac{1}{\varepsilon}) + \log \log n)$, meaning the processing time per element scales logarithmically with the sketch size.
- Extreme Reliability: An alternative analysis shows that for applications requiring an exceptionally low probability of failure, the space complexity can be tuned to feature a double-logarithmic dependence on the failure probability: $O(\frac{1}{\varepsilon} \log^2(\varepsilon n) \log \log(1/\delta))$.
Limitations and Future Work
The primary limitation is the theoretical gap between the algorithm's space bound and the known lower bound for relative-error streaming quantiles. ReqSketch achieves an exponent of $1.5$ on the logarithmic stream length factor ($\log^{1.5}(\varepsilon n)$), whereas the lower bound stands at $\Omega(\frac{1}{\varepsilon} \log(\varepsilon n))$. The authors explicitly state that closing this $O(\sqrt{\log(\varepsilon n)})$ gap remains the most prominent open question in this line of research.
Summary updated