0
0
Kafkadevops~10 mins

Deserialization in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Deserialization
Receive byte stream from Kafka topic
Apply deserializer to byte stream
Convert bytes to object/data structure
Pass object to consumer application
Use object in program logic
Deserialization converts raw bytes from Kafka into usable objects for the consumer application.
Execution Sample
Kafka
byte[] data = consumerRecord.value();
MyObject obj = deserializer.deserialize(topic, data);
process(obj);
This code takes bytes from Kafka, deserializes them into an object, then processes it.
Process Table
StepActionInputOutputNotes
1Receive messageRaw bytes from Kafka topicRaw bytesMessage arrives as bytes
2Call deserializer.deserialize()Raw bytesMyObject instanceBytes converted to object
3Pass object to process()MyObject instanceProcessed resultObject used in app logic
4EndNo more messagesStop processingNo more data to deserialize
💡 No more messages in Kafka topic, so deserialization stops.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
datanullRaw bytesRaw bytesRaw bytesRaw bytes
objnullnullMyObject instanceMyObject instanceMyObject instance
processedResultnullnullnullProcessed resultProcessed result
Key Moments - 2 Insights
Why do we need to convert bytes to an object?
Because Kafka sends data as bytes, and the consumer needs objects to work with. See execution_table step 2 where deserializer converts bytes to an object.
What happens if deserialization fails?
If deserialization fails, the consumer cannot get a usable object, so processing stops or errors. This is before step 3 in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output of step 2?
ARaw bytes
BProcessed result
CMyObject instance
DNo output
💡 Hint
Check the 'Output' column for step 2 in the execution_table.
At which step does the consumer application start using the deserialized object?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Action' column describing when the object is passed to process() in the execution_table.
If the Kafka topic has no messages, what happens according to the execution_table?
ADeserialization continues endlessly
BProcessing stops at step 4
CAn error occurs at step 2
DThe consumer creates empty objects
💡 Hint
See the 'exit_note' and step 4 in the execution_table.
Concept Snapshot
Deserialization in Kafka:
- Converts byte stream from Kafka into objects
- Uses a deserializer class/method
- Enables consumer to work with data
- Happens before processing logic
- Stops when no more messages
Full Transcript
Deserialization is the process where Kafka consumer takes raw bytes from a Kafka topic and converts them into usable objects. First, the consumer receives the raw byte stream. Then, it calls the deserializer to convert these bytes into an object. After that, the object is passed to the application logic for processing. If there are no more messages, the process stops. This flow ensures that the consumer can work with meaningful data instead of raw bytes.