Sub-O(log n) Out-of-Order Sliding-Window Aggregation

Kanat Tangwongsan, Martin Hirzel, Scott SchneiderarXiv 2018

Abstract

Sliding-window aggregation is a fundamental operation in stream processing, used for real-time analytics such as computing rolling averages or maintaining Bloom filters. While in-order data streams can be processed in $O(1)$ time, out-of-order arrivals typically necessitate $O(\log n)$ overhead using standard augmented balanced trees. This paper introduces the Finger B-tree Aggregator (FiBA), a novel data structure that achieves sub-logarithmic performance for out-of-order streams. By integrating finger-searching with a clever "position-aware" aggregation scheme, FiBA provides $O(1)$ amortized time for in-order data and $O(\log d)$ for out-of-order data, where $d$ is the distance from the window boundary. FiBA supports any associative monoid, making it applicable to a wide range of analytical tasks without requiring invertible operators.

Introduction

In modern stream processing, data often arrives out-of-order due to network delays, clock drifts, or parallel ingestion. Traditional sliding-window algorithms are optimized for in-order data, achieving constant time complexity. However, when data is disordered, systems typically fall back on augmented balanced trees (like B-trees), which increase the cost per operation to $O(\log n)$, where $n$ is the window size. For massive windows, this $O(\log n)$ cost becomes a significant bottleneck. The Finger B-tree Aggregator (FiBA) bridges this gap by exploiting the temporal locality often found in "messy" real-world data—where items are late, but usually only by a small margin.

The FiBA Algorithm

FiBA builds upon the classic B-tree architecture but introduces three critical innovations to achieve its performance targets:

1. Finger-Searching

Instead of initiating every search from the root, FiBA maintains "fingers" (pointers) to the leftmost and rightmost leaves of the tree. Since most stream data arrives near the window boundaries, the algorithm "walks up" from the finger to find the insertion point. This reduces the search time to $O(\log d)$, where $d$ is the distance from the finger, rather than the total window size $n$.

The FiBA structure utilizes fingers to optimize searches and updates near window boundaries.

2. Lazy Rebalancing

To prevent the tree structure itself from becoming a bottleneck, FiBA employs an "after-the-fact" rebalancing strategy. This ensures that the structural costs of insertion and eviction remain $O(1)$ on average, maintaining high throughput even under heavy load.

3. Position-Aware Partial Aggregates

In a standard augmented tree, changing a single leaf requires updating every ancestor up to the root. FiBA avoids this by defining four specific types of partial aggregates—up, inner, left, and right—based on a node's position relative to the tree's "spines." This allows updates to be "trapped" along the search path to a finger, preventing the need for global propagation to the root.

FiBA defines four types of partial aggregates (up, inner, left, and right) to localize updates and maintain efficiency.

Crucially, FiBA works for any monoid, meaning the aggregation operator only needs to be associative. It does not require the operator to be commutative or invertible (e.g., it supports max or complex sketches where "subtraction" is impossible).

Experimental Evaluation

The researchers evaluated FiBA using synthetic data to precisely control the out-of-order distance ($d$). They tested three aggregation operators representing different computational intensities:

  • Sum: Low cost (integer addition).
  • Geomean: Medium cost (floating-point logs).
  • Bloom Filter: High cost (maintaining a $2^{14}$ bitset).

FiBA was compared against classic augmented B-trees and state-of-the-art in-order algorithms like Two-Stacks and DABA.

Key Results and Insights

  • Performance Scaling: For in-order data, FiBA performs nearly as fast as specialized $O(1)$ algorithms. As data becomes more out-of-order, its performance degrades gracefully following a $\log d$ curve, whereas classic B-trees remain flat at a much lower performance level.
  • Latency: FiBA reduces median latency by orders of magnitude compared to classic B-trees when data exhibits temporal locality.
  • Theoretical Optimality: The authors proved that $O(\log d)$ is the best possible theoretical performance for this problem, making FiBA asymptotically optimal.
  • Window Sharing: Because it is tree-based, FiBA naturally supports range queries, allowing a single structure to serve multiple overlapping windows of different sizes without data duplication.

Limitations and Future Work

While FiBA is algorithmically superior, its "position-aware" logic is complex. On modern hardware, the additional pointers and conditional logic can lead to cache misses that may slightly offset gains for very simple operators like sum. Future work involves integrating FiBA into frameworks like Apache Flink and exploring its performance in high-throughput, bursty production environments.

Summary updated

BibTeX
@misc{tangwongsan2018sub,
  author = {Kanat Tangwongsan and Martin Hirzel and Scott Schneider},
  title = {{Sub-O(log n) Out-of-Order Sliding-Window Aggregation}},
  year = {2018},
  eprint = {1810.11308},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1810.11308},
}
Figure