#📝 Note: Sliding Window Aggregation

#Overview

A sliding window maintains an aggregate (count, sum, top-K) over a moving time interval — e.g., "tweets in the last 60 minutes." As time advances, old events age out and new events are included, giving a continuously updated view of recent activity.

#Core Idea

#Fixed (Tumbling) Window

#Sliding Window

#Bucketed Sliding Window (Approximate)

Window W = 60 min, Bucket B = 1 min, N = 60 buckets

Timeline:  [bucket_0][bucket_1]...[bucket_59]  ← circular buffer
                                                ↑ current
On new minute: drop bucket_0, add bucket_60, recompute total
Aggregation: sum(all active buckets) → O(N) but amortized O(1) per event

#Comparison

Type Memory Freshness Complexity Use Case
Tumbling window Low Low (resets at boundary) O(1) Billing, batch reports
Sliding (exact) High (store all events) Perfect O(events in W) Low-volume, exact metrics
Bucketed sliding Low (N buckets) ~1 bucket lag O(1) amortized Trending, rate limiting
Count-Min + sliding Very low ~1 bucket lag O(d×w) High-cardinality streams

#When to Use

#When NOT to Use

#Trade-offs

#Used In This Repo