Apache Flink 00:00:01 Count clicks while they are arriving An analyst wants a live count of clicks for user seven in each event-time window. Flink connects the source, keyed operator and sink into a running dataflow. The client gives the job to the JobManager, which deploys tasks into slots. The source task reads the next record of its partition and stamps the event time. The key is hashed. The record goes to the task that owns user 7. The window task adds one to the count of user 7 in local memory or RocksDB. When the watermark passes the window end, the result goes to the sink. Keying gives one task ownership of a particular key's state at a time. How that state becomes recoverable and when the window may emit a result require two other mechanisms. 00:00:48 Freeze a consistent cut of a moving stream Checkpoint seven records positions together with operator state. The job keeps running, so the boundaries on multiple input streams must describe a consistent piece of history. The JobManager starts checkpoint 7. The source saves position 50 and puts barrier 7 into the stream. With several inputs, the window task stops reading an input whose barrier has arrived, and waits for the others. All barriers are here. The state at the cut is copied in the background and the barrier moves on. The sink has prepared and everyone has reported. The JobManager declares checkpoint 7 complete. This is the aligned-checkpoint example. Other supported checkpoint modes handle in-flight records differently. In either case restore requires a completed checkpoint and a replayable source. 00:01:38 Replay thirty clicks after a failure The source has advanced from position fifty to eighty when a worker fails. Does replay add thirty extra clicks to user seven's count? Checkpoint 7 holds position 50. The job is at 80. The JobManager takes the last completed one. An unfinished checkpoint does not count. New tasks load state: count 100. The source seeks to 50. Records 51 to 80 run again. Their first effects were thrown away, so the count ends at 130. The checkpoint restores both state and source position. That protects the internal result. A database or message sink needs its own coordinated or idempotent commit to give the same external guarantee. 00:02:22 Which late clicks still count? A watermark represents event-time progress according to the job's policy. It lets a window close without requiring proof that every possible older event will ever appear. The example assigns a two-minute out-of-orderness allowance. A first event at ten oh one puts the watermark just before nine fifty-nine. An out-of-order event can still belong to a window that has not closed. The operator adds the event without moving its watermark backwards. When the watermark passes ten oh five, the example window emits a count of three. Another event for the closed window arrives with zero allowed lateness. This job routes it to its configured late-event side output. Allowed lateness and configured side outputs determine what happens to later arrivals. A watermark is a timing contract for results, not a promise about the network. 00:03:14 The silent input holds everybody back Two source partitions feed the same window operator. One stops receiving events, while the other continues. Watch which input controls the combined watermark. Both send events. The operator takes the smaller watermark. The silent partition stops advancing its watermark. Taking the minimum leaves the whole operator waiting. In this exercise a one-minute idleness timeout excludes the quiet input from the watermark calculation. Configure idleness when the source's behavior justifies it. If the quiet partition returns with old events, the late-data policy becomes relevant again. The checkpoint protects history, while the watermark governs time.