0
0
Kafkadevops~10 mins

Stream topology in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Stream topology
Define Source Topic
Create Stream from Source
Apply Transformations
Send to Sink Topic
Stream Processing Continues
A stream topology defines how data flows from source topics through processing steps to sink topics in Kafka Streams.
Execution Sample
Kafka
StreamsBuilder builder = new StreamsBuilder();
KStream<String, String> source = builder.stream("source-topic");
KStream<String, String> transformed = source.mapValues(value -> value.toUpperCase());
transformed.to("sink-topic");
This code creates a stream from 'source-topic', converts each message value to uppercase, and writes results to 'sink-topic'.
Process Table
StepActionInput MessageTransformationOutput MessageTopic
1Read messagehellononehellosource-topic
2Apply mapValueshellotoUpperCaseHELLOin-memory stream
3Write messageHELLOnoneHELLOsink-topic
4Read messageworldnoneworldsource-topic
5Apply mapValuesworldtoUpperCaseWORLDin-memory stream
6Write messageWORLDnoneWORLDsink-topic
7No more messages----
💡 No more messages in source-topic, stream processing ends.
Status Tracker
VariableStartAfter 1After 2Final
source message-helloworld-
transformed message-HELLOWORLD-
Key Moments - 2 Insights
Why does the transformed message appear after the source message in the execution table?
Because the stream reads the source message first (rows 1 and 4), then applies the transformation (rows 2 and 5), and finally writes the transformed message to the sink topic (rows 3 and 6). This order shows the flow of data through the topology.
What happens if there are no messages in the source topic?
The execution stops at step 7 as shown in the exit note, because the stream topology processes messages only when they arrive from the source topic.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output message at step 3?
Ahello
BHELLO
Cworld
DWORLD
💡 Hint
Check the 'Output Message' column at step 3 in the execution_table.
At which step does the transformation to uppercase happen for the message 'world'?
AStep 6
BStep 4
CStep 5
DStep 7
💡 Hint
Look for the 'Transformation' column where 'toUpperCase' is applied for 'world' in the execution_table.
If the source topic had no messages, what would the execution table show?
AOnly step 7 indicating no messages
BSteps 1 to 6 with empty messages
COnly steps 1 and 2
DAll steps repeated infinitely
💡 Hint
Refer to the exit_note and step 7 in the execution_table.
Concept Snapshot
Stream topology in Kafka Streams:
- Define source topic stream
- Apply transformations (map, filter, etc.)
- Write results to sink topic
- Data flows step-by-step through topology
- Processing happens as messages arrive
Full Transcript
This visual execution shows how a Kafka Streams topology processes messages. First, messages are read from the source topic. Then, each message is transformed, here by converting the value to uppercase. Finally, the transformed message is written to the sink topic. The execution table traces each step for two example messages, 'hello' and 'world'. Variables track the message values before and after transformation. Key moments clarify why the order of steps matters and what happens if no messages arrive. The quiz tests understanding of the flow and output at each step.