Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 130/ 160
07. Streaming & Real-Time Data Engineering

Flink Concepts (Windows: Tumbling, Sliding, Session; Watermarks; State Backends)

Window events, emit watermarks for lateness, and pick state backends for fault tolerance.

AdvancedWindows · Watermarks · State3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Event-time and key. Next, monotonic clock with idle sources. Finally, allowed lateness, side output, trigger, and state cleanup.

Think of it like…

Windows are different calendar bins, a watermark is the point after which the clerk rolls the old calendar page forward, and the state backend is the drawer retaining unfinished forms.

Where you’ve seen it

A 5-minute tumbling event-time window assigns at 12:00, 12:05; a 5-minute sliding window every minute has five overlaps; a 30-minute session extends on activity, with a watermark from max seen event time minus 10 minutes.

Words you’ll hear

Windows
Non-overlapping, overlapping time/count groups, or inactivity-gap groups with distinct state and output behavior.
Watermarks
A monotonic assertion that no expected event time below the bound remains, derived from source event-time observations.
State
Checkpointable operator/state storage such as heap or RocksDB selected by state size and recovery behavior.
Operational boundary
A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely. Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

Visual diagram

Loading interactive diagram

Theory & deep dive

Windows: the working mechanism

Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts.

Event-time and key. Monotonic clock with idle sources, then tumbling/sliding/session state and TTL; this exposes the state governed by State.

Flink Concepts in one concrete design

A 5-minute tumbling event-time window assigns at 12:00, 12:05; a 5-minute sliding window every minute has five overlaps; a 30-minute session extends on activity, with a watermark from max seen event time minus 10 minutes.

Key takeaway: Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts

Flink Concepts: failure mode and production response

A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.

Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events. Track Watermark lag as "max event time minus emitted watermark", and make Window overlap visible to the dataset owner.

Key takeaway: Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

How it works, step by step

Step 1 of 4
Windows

1. Assign events

Event-time and key. Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts.

event-time and key
Key numbers at this step
Watermark lag
max event time minus emitted watermark
Watermarks
A monotonic assertion that no expected event time below the bound remains, derived from source event-time observations.

When to use it & trade-offs

What it is

Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts. A 5-minute tumbling event-time window assigns at 12:00, 12:05; a 5-minute sliding window every minute has five overlaps; a 30-minute session extends on activity, with a watermark from max seen event time minus 10 minutes.

Why it matters: A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely. Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

When to reach for it

  • Window events, emit watermarks for lateness, and pick state backends for fault tolerance.
  • Choose Windows because it provides this capability: Non-overlapping, overlapping time/count groups, or inactivity-gap groups with distinct state and output behavior.
  • Keep evidence for Watermark lag at "max event time minus emitted watermark" so the last production stage-Emit/clean - allowed lateness, side output, trigger, and state cleanup-remains testable.

When to avoid or be careful

  • A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.
  • Do not conflate Watermarks with Windows. The second concept contributes different behavior: A monotonic assertion that no expected event time below the bound remains, derived from source event-time observations.
  • Release only after this guardrail is in place: Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

Windows / Watermarks / State - roles, limits, and operating cost

Windows
Best for: Non-overlapping, overlapping time/count groups, or inactivity-gap groups with distinct state and output behavior.

Strengths: Non-overlapping, overlapping time/count groups, or inactivity-gap groups with distinct state and output behavior. Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts.

Watch out: A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.

Watermarks
Best for: A monotonic assertion that no expected event time below the bound remains, derived from source event-time observations.

Strengths: A monotonic assertion that no expected event time below the bound remains, derived from source event-time observations. In this workflow it supports: Accumulate window - tumbling/sliding/session state and TTL.

Watch out: The operating cost is real: tumbling 1x, sliding size/slide factor.

State
Best for: Checkpointable operator/state storage such as heap or RocksDB selected by state size and recovery behavior.

Strengths: Checkpointable operator/state storage such as heap or RocksDB selected by state size and recovery behavior. Its output can be checked with State TTL.

Watch out: Operating guardrail: Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for Windows, and how would Watermark lag reveal it?”
  • “Why is Watermarks distinct from this behavior: checkpointable operator/state storage such as heap or RocksDB selected by state size and recovery behavior?”
  • Production clue: A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.
  • Design probe: Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

Benchmarks & rules of thumb

Watermark lag -
max event time minus emitted watermark
Window overlap -
tumbling 1x, sliding size/slide factor
State TTL -
covers windows/joins plus allowed lateness, then clears

Common mistakes & follow-ups

Common interview mistakes

  • A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.
  • Reporting success from a job exit code without checking Watermark lag and Window overlap.
  • Treating this example as complete without replay, rollback, or access boundaries: A 5-minute tumbling event-time window assigns at 12:00, 12:05; a 5-minute sliding window every minute has five overlaps; a 30-minute session extends on activity, with a watermark from max seen event time minus 10 minutes.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: Non-overlapping, overlapping time/count groups, or inactivity-gap groups with distinct state and output behavior.
  • What does the recovery plan do when this occurs? A tumbling window with late events can close early under a low watermark, overlapping sliding windows multiply state, and session gaps plus no max duration can retain one hot key indefinitely.
  • When is Windows insufficient for Window overlap, and what does adding Watermarks cost in Watermark lag?
Interview tip: Lead with the data path and failure boundary: Flink windows group events into tumbling, sliding, or session intervals, watermarks advance event-time progress, and state backends persist keyed state across checkpoints and restarts. Then make the answer operational: Measure source idleness and event lateness, generate/propagate monotonic watermarks with idle detection, choose state TTL/window cleanup, and set side outputs/allowed lateness for correction events.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Flink Concepts (Windows: Tumbling, Sliding, Session; Watermarks; State Backends) with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Real-Time Stream Processing with Apache Flink
Next topic
Kafka Streams & ksqlDB for Lightweight Stream Transformations