← Complete program

Chapter 18 · Course 4 c18-m04

How do we test continuous processing?

Your goal Link source, event time, watermark, window, state, and checkpoint in a streaming stop-and-restart test.

The lesson, the vocabulary, the worked example and the mission are separate blocks. You can follow them in order or return to the one you need.

Video explanation

This English explanation has English subtitles. Its examples may use a separate practice dataset; use the data stated in the written mission for your answers.

01

Story · optional context

The story so far

You are Aster Motors' new data recruit. Luca was hurt when a car resembling the missing Noctis 01 prototype crashed, and Voss wants to blame you. Imani recovered OPEN-18, which arrived after the crash yet carries an earlier event time. A window keeps this late command and the calculation can restore its state after a failure. Voss demands one demonstration: show the stream, windows, and restart, or the corrected timeline will be dismissed.

This lesson stands alone. Flink is a tool for processing data streams as messages arrive. It can read Kafka, use event time, calculate windows, and checkpoint state for restart. You will read an illustrative Flink SQL plan and run a Python simulator without a server. The aim is to prepare and check a small laboratory before using its result in the investigation; this page does not run a Flink installation.

02

Before the lesson

Purpose of this course

Link source, event time, watermark, window, state, and checkpoint in a streaming stop-and-restart test.

Topics covered

Explain a message's path from a practice Kafka topic to a Flink window.; Read a table definition, event-time column, and watermark rule.; Check that OPEN-18 remains in its correct window although it arrives after the crash signal.; Plan a failure test comparing restored output with an uninterrupted run, including the external sink.

What you will learn

  • Explain a message's path from a practice Kafka topic to a Flink window.
  • Read a table definition, event-time column, and watermark rule.
  • Check that OPEN-18 remains in its correct window although it arrives after the crash signal.
  • Plan a failure test comparing restored output with an uninterrupted run, including the external sink.

PART 1 · THE LESSON

Understand step by step

1

Lesson · explanation

A continuous stream connects source records to a report

Voss shows a chart without OPEN-18, yet Imani holds message E2 carrying that command, received after the crash signal. To explain the difference, follow the message through the whole path: Kafka topic, Flink reader, event-time extraction, watermark, ten-minute window, and published result. Each stage affects what appears on screen. A data engineer cannot conclude that the command never existed merely because it is absent from an old report screenshot.

Imagine a mail-sorting line. A letter enters a box, passes a date reader, joins a time-labeled tray, and appears on a printed list. If it arrives late, an earlier list may omit it even though its written date belongs to a previous tray. The letter has not necessarily vanished. Ask when the tray was considered complete and whether another list was produced. The stream report needs the same questions.

The practice Kafka source contains E1/OPEN-17, a crash signal, E2/OPEN-18, and a progress message called HEARTBEAT. HEARTBEAT is not a door command; it advances the greatest observed event time. The Flink table declaration describes the fields and converts event_at_ms, a UTC epoch value in milliseconds, into time for windows. A text fragment such as '21:18' is not a substitute for that number in the illustrative SQL.

This page describes a laboratory to reason about. Running the SQL would require Flink, its Kafka connector, and an authorized local broker, none of which is necessary to answer the mission. Topic names are fictional, and no physical door is controlled. Draw the four records on paper if helpful. The purpose is to understand what the chart shows and what it may omit because of late arrival or an interruption.

Pause and think

What path does E2 follow before appearing in a window report?

See the explanation

Kafka topic → Flink read → event time → watermark → ten-minute window → versioned output.

2

Lesson · explanation

Event time and arrival time answer different questions

E2 reaches the system at 21:36 but carries an event time of 21:18. The first time records when the receiving machine saw it. The second claims when the source event occurred. To group commands by the period of the event, the window uses 21:18. If it used only 21:36, E2 would be grouped with later records and could appear to follow the crash for the wrong reason. The eighteen-minute gap requires investigation, not erasure.

Imagine a postcard written on Monday and delivered on Wednesday. Delivery day is not writing day. The writer might also have put the wrong date on the card, so the postmark and writing should be verified separately. For E2, 21:18 comes from the message and 21:36 comes from receipt. This lesson explains how Flink can use the first value. It does not establish that the door controller's clock was accurate.

E1 has event time 21:05 and belongs in [21:00,21:10). The left bracket includes 21:00; the right parenthesis excludes 21:10. E2 has event time 21:18 and belongs in [21:10,21:20). An event stamped exactly 21:20 goes in the next window. Writing the boundaries prevents the same instant from being counted in two neighboring windows.

The crash signal in the practice sequence carries event time 21:25 and raises the maximum observed event time to 21:25 before the late arrival of E2. This maximum is calculated from message timestamps, not read directly from a wall clock. In the mission, draw two lines if necessary: order of arrival on one and time declared by each event on the other. They tell different parts of the story.

Pause and think

Which windows contain E1 at 21:05 and E2 at 21:18?

See the explanation

E1 belongs in [21:00,21:10) and E2 in [21:10,21:20), using event time.

3

Lesson · explanation

A watermark states how far event-time progress has reached

A watermark is a marker of progress in event time. The practice rule allows twenty minutes of disorder by subtracting twenty minutes from the greatest event time observed. After the crash signal raises that maximum to 21:25, the illustrative watermark is 21:05. Under this simplified rule, records dated later than that marker may still arrive in time for their windows. E2 is dated 21:18, and its window ends at 21:20; the 21:05 watermark has not closed it.

Imagine a host who allows guests a twenty-minute grace period before closing registration for a time slot. Seeing a guest dated 21:25 does not instantly close the earlier [21:10,21:20) slot. When E2 arrives at 21:36 but declares 21:18, it can still join that slot in this simulation. This gives a plausible technical explanation for Voss's chart: an early version can omit E2 while a later window result includes it.

The exercise's HEARTBEAT carries event time 21:45. The greatest observed time becomes 21:45, and the illustrative watermark rises to 21:25. It has now passed the 21:20 end of E2's window, which may be emitted under the laboratory plan. HEARTBEAT itself adds zero door openings. Counting a progress message as OPEN-18 or another command would inflate the result and mislead the investigation.

A real Flink job may consume several partitions and sources. Effective progress depends on their watermarks, idle-source handling, and configuration; the slowest active input can matter. Therefore 21:25 minus 20 equals 21:05 is an illustration, not a universal prediction for every installation. To diagnose an actual stream, inspect observed watermark values, partitions, idleness settings, and late-record rules rather than relying on this paper calculation alone.

Pause and think

What illustrative watermark holds when E2 arrives, and why is E2's window open?

See the explanation

21:25 − 20 minutes = 21:05; it has not crossed the 21:20 end of E2's window.

4

Lesson · explanation

A window counts commands, while output keeps a version

A window groups events by a time period. Here the plan groups commands into ten-minute intervals based on event time. E1/OPEN-17 belongs to 21:00–21:10; E2/OPEN-18 belongs to 21:10–21:20. The crash signal and HEARTBEAT may help advance event-time progress but are not door-opening commands to count. The practice query should filter useful message types and count distinct command identifiers within the relevant window.

Imagine trays marked with ten-minute intervals. An OPEN-18 card delivered late goes into the 21:10 tray because of the event time written on it. If an identical OPEN-18 identifier is delivered twice, a distinct count in that tray can still show one. But a window's distinct count alone does not guarantee that a real door opens only once or that an external report sink is written only once after a crash. Define the scope of each check.

A report may have versions: one published before late messages have been considered and another after the watermark advances or a correction is made. Preserve the version identifier and publication time of each. If Voss presents an older screenshot without OPEN-18, Imani should ask which version it depicts, then compare it with raw E2 and the window rules. A difference between screenshots is not by itself proof of fraud; the window may have still been open.

For the mission, write what the report should contain after E2's window can close in the simulation: OPEN-18 belongs to [21:10,21:20). Then state what still needs checking: the result actually published, any later revisions, and records rejected as too late by the running engine. Window logic aids investigation only when output versions can be traced back to source messages.

Pause and think

Does the 21:45 HEARTBEAT add a door opening to the count?

See the explanation

No. It advances observed event-time progress and the watermark, but is not a door command.

5

Lesson · explanation

A checkpoint prepares recovery after a processing stop

A checkpoint is a coherent snapshot of a continuous computation's state at a known point. State may include source progress, windows still open, and commands already seen. If Flink stops, it can restore a confirmed snapshot and continue. To test this, Mara injects known practice messages into an authorized lab, waits for a completed checkpoint, notes windows and results, then causes a controlled stop after a documented point.

Imagine a video game that saves your progress. After the console stops, you resume from the save instead of the beginning. But seeing the screen return is not enough to prove the save worked: compare your inventory and location with a run that never stopped. For the stream, compare command IDs, window results, and report versions with an uninterrupted reference run. E2 should not disappear or create a duplicate final effect.

The mission protocol is concrete: prepare messages with known IDs and times; record the uninterrupted output; replay the same input; wait for a confirmed checkpoint; stop the engine at a documented moment; restore from that checkpoint; compare late records, window counts, and output versions. Keep source offsets, checkpoint logs, and watermark configuration to explain any difference. A test without the expected reference would be hard to interpret.

Restoring internal state does not by itself guarantee a correct external destination. A result might be written to a separate database just before failure and written again after recovery. Test that sink separately with stable result identifiers and an idempotent or transactional write design. 'Flink has a checkpoint, therefore the external report is unique' is too broad. The checkpoint and the final side effect are related but distinct protections.

Pause and think

What should a restored run be compared with?

See the explanation

Compare useful messages, windows, output versions, and the external sink with an uninterrupted reference run.

6

Lesson · explanation

A technical timeline does not identify a human actor

The lab can show that E2/OPEN-18 belongs in the 21:10–21:20 interval despite arriving at 21:36, and that a controlled restart retains the result. That is important technical evidence for the story. It does not prove that the door controller's clock was accurate. If its clock was wrong, event_at_ms could place the command in the wrong window. Compare the controller time with another trustworthy time source before treating the event order as physical fact.

The message may also carry SUPPLIER-SVC. That is a service account, not a person's name. Depending on the system, several processes or users could have access to its credentials. To learn who caused the opening, Imani needs access logs, authorizations, key-change history, and physical evidence. Stream analysis tells her which records and versions to inspect; it does not deliver a verdict against Voss or the new recruit.

Imagine a letter signed 'supplier office.' It identifies a department named on the paper, not the hand holding the pen. Even a consistent timestamp and a well-retained message do not remove that distinction. The continuing story therefore has two open questions: the true physical timeline of the command and the person behind the technical key. The next lessons investigate access records and the custody of evidence.

To answer the mission, draw the full path, place E1 and E2 in their windows, calculate watermark 21:05 at E2's arrival and 21:25 after HEARTBEAT. Then describe a confirmed-checkpoint stop-and-restart test against an uninterrupted reference, including the external sink. End with limits: inspect the versioned report, verify the door clock, and do not infer a human identity from SUPPLIER-SVC. This makes the timeline defensible without overstating it.

Pause and think

What three matters still need checking after the lab succeeds?

See the explanation

The external sink after failure, the controller clock's accuracy, and the person behind SUPPLIER-SVC.

Visual guide

Path through the streaming test

  1. 1Practice Kafka: E1, CRASH, E2, HEARTBEAT
  2. 2Flink: event_at → watermark → windows
  3. 3State/checkpoint: saved positions and calculation
  4. 4Sink: versioned report, then stop-and-restart test

The simulator explains the principle; a real deployment needs a configured source, connector, and sink.

Code · read each line

Simulate the stream and progress locally

from datetime import datetime, timedelta
def at(hm): return datetime.fromisoformat("2026-04-12T"+hm+":00+00:00")
events=[
 {"id":"E1","kind":"gate","command":"OPEN-17","at":at("21:05"),"received":at("21:07")},
 {"id":"CRASH","kind":"signal","command":None,"at":at("21:25"),"received":at("21:26")},
 {"id":"E2","kind":"gate","command":"OPEN-18","at":at("21:18"),"received":at("21:36")},
 {"id":"HEARTBEAT","kind":"progress","command":None,"at":at("21:45"),"received":at("21:46")},
]
seen=set()
buckets={}
max_event=None
for e in sorted(events,key=lambda row:row["received"]):
    max_event=e["at"] if max_event is None else max(max_event,e["at"])
    watermark=max_event-timedelta(minutes=20)
    if e["kind"]=="gate" and e["command"] not in seen:
        seen.add(e["command"])
        start=e["at"].replace(minute=(e["at"].minute//10)*10,second=0)
        buckets.setdefault(start,[]).append(e["command"])
    print(e["id"],"watermark",watermark.strftime("%H:%M"))
print("gate_windows",[(k.strftime("%H:%M"),v) for k,v in sorted(buckets.items())])
print("distinct_commands",len(seen))

The script reads by arrival but places E2 at 21:18. Its illustrative watermark is 21:05 when E2 arrives and 21:25 after HEARTBEAT; OPEN-17 and OPEN-18 remain distinct.

Configuration · read the values

Illustrative Flink SQL laboratory plan

-- Illustration: requires a configured Flink SQL client and Kafka connector.
CREATE TABLE gate_events (
  event_id STRING,
  kind STRING,
  command_id STRING,
  service_identity STRING,
  event_at_ms BIGINT,
  event_at AS TO_TIMESTAMP_LTZ(event_at_ms, 3),
  WATERMARK FOR event_at AS event_at - INTERVAL '20' MINUTE
) WITH (
  'connector' = 'kafka',
  'topic' = 'gate_commands_practice',
  'properties.bootstrap.servers' = 'localhost:9092',
  'properties.group.id' = 'flink_gate_practice',
  'scan.startup.mode' = 'earliest-offset',
  'format' = 'json'
);
SELECT window_start, window_end, COUNT(DISTINCT command_id) AS commands
FROM TABLE(
  TUMBLE(TABLE gate_events, DESCRIPTOR(event_at), INTERVAL '10' MINUTE)
)
WHERE kind = 'gate'
GROUP BY window_start, window_end;

The table converts event_at_ms to event time and defines a watermark. The query groups ten-minute windows and counts distinct commands. It needs a Flink SQL client and Kafka connector; verify JSON, partitions, and the sink before a real test.

PART 2 · WATCH IT WORK

A complete worked example

Follow each step, then the result

Worked example: E2 despite late receipt

E2 arrives at 21:36 with event time 21:18. The crash signal raised maximum observed event time to 21:25 and the rule subtracts twenty minutes.

  1. Calculate illustrative watermark: 21:25 minus 20 minutes is 21:05.
  2. Place E2 in [21:10,21:20); watermark 21:05 has not crossed the window end.
  3. At the 21:45 progress event, recompute 21:25 and see that the window can be emitted.
  4. Compare the report with a restored run and keep the published version as evidence.
What this shows

A late arrival can still enter its event-time window; closure depends on event-time progress and failure requires a recovery check.

How this helps with your mission

The worked example follows E2: event time 21:18, arrival 21:36, illustrative watermark 21:05 after the 21:25 crash signal, then 21:25 after the 21:45 HEARTBEAT. Place E1 in [21:00,21:10) and E2 in [21:10,21:20). Trace topic, event time, watermark, window, and output. Propose a confirmed-checkpoint test with stop, restore, and comparison against an uninterrupted run, including the external sink. This helps Imani challenge a chart without OPEN-18 while leaving the real controller clock and the human behind SUPPLIER-SVC unresolved.

PART 3 · YOUR TURN

Use the lesson to solve the mission

Story scene · practical task

Mission: prove the timeline under failure

Voss enters with a graph that omits OPEN-18. Mara starts the practice laboratory while Imani places the late message on the table. Explain each stage and how you would check the result if the engine stops halfway. The meeting is near in the story; the exercise has no timer.

Your task

  1. Draw topic Kafka → event time → watermark → window → report.
  2. Put E1 and E2 in their windows and calculate the watermark when E2 arrives.
  3. Give a stop-and-restart test using a confirmed checkpoint and an uninterrupted comparison.
  4. Name what this lab cannot yet prove about the sink, clock, and SUPPLIER-SVC.

How to know you have succeeded

  • Source and calculation in the right order.
  • E1 in [21:00,21:10), E2 in [21:10,21:20), watermark 21:05 when E2 arrives.
  • Confirmed checkpoint, stop, restore, command and report comparison.
  • External sink, clock, and human identity still require verification.
Open this mission in the browser workspace

Try code or SQL and keep a local draft. The mission questions are checked separately below.

Check the facts in your mission

Answer each factual question, then write your report in your own words. The program checks the choices; compare the report with the worked answer below.

1. What path does a message follow before a window report?
2. Where do E1 at 21:05 and E2 at 21:18 belong by event time?
3. What illustrative watermark applies when E2 arrives after the 21:25 signal?
4. What does the 21:45 HEARTBEAT do in the copy?
5. Which trial checks that processing survives a failure?
See the worked answer
  1. The topic supplies messages. Flink reads event time, generates a watermark, groups commands in windows, and writes a versioned report.
  2. E1 at 21:05 belongs in [21:00,21:10). E2 at 21:18 belongs in [21:10,21:20). After the 21:25 signal, the illustrative watermark is 21:05, so E2 can arrive before its window closes.
  3. Inject known messages, record results, wait for a successful checkpoint, stop, restore, and compare against an uninterrupted run. Inspect late records and versions.
  4. An external sink may duplicate writes; test idempotent or transactional behavior. Verify the gate clock. SUPPLIER-SVC does not identify a person.

The technical timeline now withstands delay and a controlled failure. The next chapter investigates who may have acted behind the technical identity using access records.

Before you leave

Remember this

  • The stream runs from Kafka topic through Flink, event time, watermark, window, and published output.
  • E1 at 21:05 belongs in [21:00,21:10); E2 at 21:18 belongs in [21:10,21:20) despite arriving at 21:36.
  • In the simplified global simulation, the watermark is 21:05 after the 21:25 signal and 21:25 after the 21:45 HEARTBEAT.
  • HEARTBEAT advances observed event time without counting as a door-opening command.
  • A restart test compares restored results with an uninterrupted run and checks the external sink separately.
  • The lab proves neither the controller clock's accuracy nor the human behind SUPPLIER-SVC.
A–Z

Part of the lesson · keep nearby

New words, explained

These are the names of ideas used in the lesson above. Return here whenever a word feels unfamiliar.

Flink
An engine that calculates over data streams, including continuous ones.
Stream table
A table-like view of incoming messages that Flink can query.
Kafka connector
The configured component allowing Flink to read a Kafka topic.
Event time
When the source says the fact occurred; it places a message in a window.
Watermark
An estimate of event-time progress that helps trigger a window.
Ten-minute window
A group of facts with event times inside one ten-minute interval.
Checkpoint
A coordinated save of state and reading positions for recovery.
Stop-and-restart test
An experiment that interrupts processing and checks the result after restoration.

Official references