Apache Flink
maang.io System Design Series
Apache Flink processes streams a record at a time (not micro-batches), with first-class support for the hard parts of streaming: event time vs processing time, watermarks for out-of-order data, windowing, and large managed state. Its exactly-once guarantee comes from asynchronous barrier snapshots (the Chandy-Lamport algorithm). It's the go-to for stateful, low-latency stream processing.
This deep dive comes in three parts:
- Foundations & Core Concepts β streams, event time, and watermarks.
- Internals β windowing, keyed state (RocksDB backend), and checkpointing/exactly-once, with worked numbers.
- Interview β Staff/Principal Q&A: event-time reasoning and Flink vs Storm vs Spark.
Apache Flink β Part 2: Internals & Exactly-Once
maang.io System Design Series
What is this?
Back to our sorting office. In Part 1 we watched clerks handle letters off the belt, reason about postmarks, and seal date-labelled bins. Now we go behind the scenes: who assigns clerks to sections of the belt (the runtime), where a clerk keeps the running ledger when the pigeonholes overflow (state backends), and β the crown jewel β how a supervisor photographs the entire floor at one consistent instant while the belt keeps moving, so a blackout never loses or double-counts a letter (checkpoints via barrier snapshotting).
That last trick is what earns Flink its reputation. Getting a globally consistent snapshot of a distributed system without stopping it sounds impossible. Flink does it with an elegant algorithm β asynchronous barrier snapshotting β and if you understand nothing else from this chapter, understand that. It's the difference between "exactly-once" being a marketing slogan and an actual guarantee.
The one-line idea: Flink's runtime turns your dataflow into parallel subtasks, keeps per-key state locally (heap or RocksDB), and periodically floats checkpoint barriers through the stream. When every operator has snapshotted its state at the same logical barrier, Flink has a consistent global snapshot it can restart from β so on failure it rewinds the sources and restores state, reprocessing nothing more and nothing less than it must. That's exactly-once.
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson