0
0
Kafkadevops~10 mins

Punctuators for time-based triggers in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Punctuators for time-based triggers
Start Stream Processing
Schedule Punctuator
Wait for Time Interval
Punctuator Triggered
Execute Punctuator Logic
Continue Processing Records
Back to Wait for Time Interval
The flow shows how Kafka Streams schedules a punctuator to run repeatedly at fixed time intervals, triggering custom logic while processing stream records.
Execution Sample
Kafka
streamProcessorContext.schedule(Duration.ofSeconds(10), PunctuationType.WALL_CLOCK_TIME, timestamp -> {
    System.out.println("Punctuator triggered at " + timestamp);
});
This code schedules a punctuator to run every 10 seconds, printing the current timestamp each time it triggers.
Process Table
StepActionTime (seconds)Punctuator Triggered?Output
1Start stream processing0No
2Schedule punctuator every 10 seconds0No
3Wait until 10 seconds elapsed10YesPunctuator triggered at 10
4Execute punctuator logic10YesPrinted timestamp 10
5Wait until 20 seconds elapsed20YesPunctuator triggered at 20
6Execute punctuator logic20YesPrinted timestamp 20
7Wait until 30 seconds elapsed30YesPunctuator triggered at 30
8Execute punctuator logic30YesPrinted timestamp 30
9Stop stream processing30+NoStream closed
10ExitNoPunctuator stops as stream ends
💡 Stream processing stopped, so punctuator no longer triggers.
Status Tracker
VariableStartAfter 10sAfter 20sAfter 30sFinal
timestamp0102030Stream ended
Key Moments - 3 Insights
Why does the punctuator trigger at exact intervals even if no records arrive?
Because the punctuator is scheduled with WALL_CLOCK_TIME, it triggers based on real time passing, independent of record arrival, as shown in execution_table rows 3, 5, and 7.
What happens if the stream processing stops before the next punctuator time?
The punctuator stops triggering because the stream is closed, as shown in execution_table row 9 and exit_note.
Can the punctuator modify state or produce output?
Yes, the punctuator logic runs inside the scheduled callback and can update state or produce output, demonstrated by the printed timestamp in execution_table outputs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the timestamp value when the punctuator triggers for the second time?
A10
B30
C20
D0
💡 Hint
Check the 'Time (seconds)' column at the second punctuator trigger in execution_table row 5.
At which step does the stream processing stop, causing the punctuator to stop?
AStep 8
BStep 9
CStep 7
DStep 10
💡 Hint
Look at execution_table row 9 where the stream is stopped.
If the punctuator was scheduled every 5 seconds instead of 10, how would the output change by step 6?
AIt would trigger twice as often, so output at 5 and 10 seconds.
BIt would trigger less often, only once at 10 seconds.
CIt would not trigger at all.
DIt would trigger only once at 20 seconds.
💡 Hint
Refer to the 'Time (seconds)' and 'Punctuator Triggered?' columns in execution_table to understand timing.
Concept Snapshot
Punctuators in Kafka Streams run code at scheduled time intervals.
Use streamProcessorContext.schedule() with a Duration and PunctuationType.
WALL_CLOCK_TIME triggers based on real time, independent of record flow.
Punctuator callback receives the current timestamp.
Useful for periodic tasks like flushing or state cleanup.
Full Transcript
This visual execution shows how Kafka Streams uses punctuators to run code at fixed time intervals. The stream starts and schedules a punctuator every 10 seconds. The punctuator triggers at 10, 20, and 30 seconds, printing the timestamp each time. The variable 'timestamp' updates accordingly. When the stream stops, the punctuator stops triggering. Key points include that punctuators run on real time, can run even without new records, and stop when the stream ends.