Introduction

If you are new to Kafka, I would recommend you learn about why Kafka came into existence in software development. Then you can visit this article, Getting Started With Apache Kafka: Introductory Guide.

Kafka Terminologies

From below onwards, we will be having a quick high-level overview of different Kafka terminologies and their related components.

Note. Kafka Consumers and producers are basic client APIs through which we can interact with Kafka.

Kafka Client APIs

There are two advanced client APIs that come with Kafka.

Note. With Kafka Connect, we can perform the data movement in and out of Kafka without writing a single line of code.

If I have to summarize this as a whole, we have four client APIs such as the Producer API, Consumer API, Connect API, and Streams API, using which we can interact with Apache Kafka, and in one frame, it will look like this.

Producer API

Kafka Topics and Partitions

Points to remember

Internal Working of Apache Kafka

Now, let's put these concepts together and then see how they work. Since we know all the important terminologies and concepts of Kafka, we can combine them and see how it works internally.

In Kafka, we have the producer and consumer. We have the Kafka producer because the producer is what is fundamentally needed to produce a new record in Kafka. Producers, in general, produce a message on the topic if something outside invokes a producer. The producer has complete control over which partition the message is going to go.

The producer uses the topic name to produce a message, so when the message is sent from the producer, it first reaches the Kafka topic.

Once the poll notices this message, it is consumed by the consumer, and the consumer does some processing on the retrieved record. The behavior of Kafka consumers is to pull continuously for new messages. So, the consumer is pulling the broker using the topic name.

So, if we have a use case where we would like to publish and read the records in a certain order, then we have to make sure to publish the records to the same partition. Let's say we are sending a new message that goes to Partition Zero.

Now, the offset is incremented from 1 to 1, and it gets appended to the existing log. Then, we are going to send another message to partition one: the offset is increased from 1 to 2, and it is appended to the partition log, and it continues to do the same as new records are produced into the Kafka topics.

One quick thing to note out here is that even though the record is read by the consumer, the message still resides inside the Kafka as per the defined retention time.

Conclusion

This makes it to the end of the article, where we learned some concepts, which are mentioned below.

Disclaimer on photos used: All photos used in the above article are either taken from Udemy or Google. Copyright is authorized to respective owners.