Kafka: Event

Learn
2 min readJul 9, 2024

--

Event is a thing that has happened.

Don’t read the text on the image

Thing can be a goal scored in the semi finals, a user hovering over a link, a package getting delivered, an invoice becoming past due, a microservice completing a defined portion of it’s flow, a thermostat reporting that temperature is beyond threshold.

Event as described as the thing above is clearly a state. You definitely notice the state there. An invoice is past due. It is now a cause of concern. A microservice completed part of it’s work. It is relaxed, drinking a bottle of water, throwing water on his face.

The other thing about an event is the annouciness of it. There is a declaration. I declare that I cleared the 500 K mark in my annual salary, Usain Bolt raises his lanky arms and declares that the gold medal would hang over his green jersey.

Event is notification plus state.

How is event represented in Kafka? As a key-value pair. Value is what you look at. That is where all the talk above attains relevance. Key is NOT a primary key. The key does not uniquely identify the value. Key is more like a context for the value. There can be multiple key value pairs for the same key. Key is the villain in your flick, and value is a punch on his face, a value is a kick in his stomach, value is a shove on his shoulder, a value is a jab on his chin. The key is the same. Counter intuitive.

Event abstraction sits in the value.

Value is typically the domain object. A placed order, a sold item. It can also be the representation of the sensor data from the thermostat.

As far as kafka is concerned, key is a byte stream. Value is a byte stream. Ultimately, that is all life is in the digital world. Everything is a byte stream.

But when you want to do business with the byte stream, you want to be able to infer information out of it. So, you may want to make an order out of the value bytestream. Sure you can. You have to declare your deserializer that would tell you exactly where the villain was punched.

Serialized representation would be in JSON, AVRO, protocol buffer formats. And you deserialize those into real people.

Event is the base nucleus abstraction where your solution built using kafka rests. The K V pairing, the serialization deserialization, and the key not being a PK. Once you know these, you can close the page.

--

--

Learn
Learn

Written by Learn

On a continuing learning journey..

Responses (1)