Start here
Apache Flink is a stream engine. It reads events one at a time, keeps state, and writes results. Many teams run it on Kafka.
The chapter "Stream Processing" showed the ideas: state, windows, watermarks and checkpoints. This chapter shows how Flink does them, because senior interviews ask how it works inside.
What you already know
- State is what a job remembers between events, such as a running total.
- A watermark decides when a window of event time is done.
- A checkpoint saves the state and the input position together.
- Exactly-once means the result is as if each event was handled once. The sink must help.
What you will learn
- How a Flink job runs on a cluster.
- Where state lives, and how to choose the state backend.
- How Flink takes a checkpoint while data keeps flowing.
- How it restarts after a crash.
- Savepoints: how to change a job without losing its state.
- Two-phase commit: exactly-once into Kafka.
- Backpressure: what a slow sink does to the whole job.
- When to choose Flink, and when Spark is enough.
We use the seven shop orders from "Streaming Architecture Fundamentals". The job sums revenue for each customer:
| offset | order_id | customer_id | amount |
|---|---|---|---|
| 0 | 110 | 2 | 30.00 |
| 1 | 111 | 5 | 9.00 |
| 2 | 112 | 3 | 20.00 |
| 3 | 113 | 1 | 12.00 |
| 4 | 114 | 4 | 7.50 |
| 5 | 150 | 2 | 18.00 |
| 6 | 151 | 1 | 8.00 |
-- For each customer: the total of all their orders so far.| customer_id | revenue |
|---|---|
| 1 | 20.00 |
| 2 | 48.00 |
| 3 | 20.00 |
| 4 | 7.50 |
| 5 | 9.00 |
