Windowing Concepts
You'll learn how tumbling, sliding, and session windows let you aggregate unbounded streaming data into meaningful, time-bounded chunks.
Why Windowing?
Streaming data is infinite—events arrive continuously without end. To perform aggregations (counts, sums, averages) on this endless flow, you need to divide time into finite windows. Each window defines a time boundary over which you compute results, then emit them downstream.
Three Core Window Types
Tumbling Windows
Fixed-size, non-overlapping intervals that march forward in lockstep. Every event belongs to exactly one window.
- Example: 5-minute windows starting at :00, :05, :10...
- Use case: "Count logins every 5 minutes."
- Think: Ice cube trays—each slot is separate.
Sliding Windows
Fixed-size windows that slide forward by a smaller interval, creating overlaps. Events can appear in multiple windows.
- Example: 10-minute windows sliding every 1 minute.
- Use case: "Moving average of CPU usage over the last 10 minutes, updated every minute."
- Think: A moving spotlight scanning across time.
Session Windows
Dynamic windows that group events separated by inactivity gaps (timeouts). No fixed size—they grow as events arrive and close after silence.
- Example: 30-minute inactivity gap defines session boundaries.
- Use case: "Analyze user activity sessions on a website."
- Think: Chapters in a conversation—they end when someone stops talking.
Event Time Matters
Windows typically operate on event time (when the event actually occurred), not processing time (when your system saw it). This ensures accuracy even when events arrive late or out-of-order.
Key Takeaway: Tumbling windows partition time cleanly, sliding windows provide continuous overlapping views, and session windows dynamically capture bursts of activity—choose based on whether you need discrete snapshots, smooth transitions, or behavior-driven grouping.