DEV Community

Batrudin Jamaludin
Batrudin Jamaludin

Posted on

The Ultimate Guide to Apache Kafka: Basics, Architecture, and Core Concepts

Apache Kafka is a powerful open-source distributed streaming platform used to handle real-time data feeds. It was Originally developed by LinkedIn and later open-sourced in 2011, Kafka is now one of the most popular tools for building real-time data pipelines and streaming applications. Similar to other distributed systems, Kafka boasts a complex architecture, which may pose a challenge for new developers. Setting up Kafka involves navigating a formidable command line interface and configuring numerous settings. In this guide, I will provide insights into architectural concepts and essential commands frequently used by developers to initiate their journey with Kafka.

Understanding Apache Kafka Basics

Kafka is different from traditional messaging systems because it allows data to be published, consumed, and stored across a distributed network of servers, enabling real-time data processing.

Some of the key concepts of Kafka include: clusters, Topic, Producer, Consumer, Partitions and Connect.

Kafka’s Architecture

The architecture of Kafka is designed to be highly scalable, fault-tolerant, and efficient. It is built around a few core components:

  • Topic: Topic is Streams of records that Kafka organizes data into. It is the equivalent of tables that hold records in a relational database. A topic can have multiple partitions, allowing data to be distributed across different Kafka brokers, improving scalability and fault tolerance.

  • Producer: The producer is applications that write data to kafka topic and are responsible for sending message to kafka topic through Kafka’s client libraries. Examples include a microservice, web application or any other system that generates real time data.

  • Consumer: The consumer is applications that read data from kafka's topics. Kafka supports multiple consumers that can consume messages from the same topic independently. Consumers are often part of a consumer group to enable parallel processing of data and fault tolerance.

  • Broker: Its a Kafka server instances that receive, store and forward messages. Multiple brokers work together to form a Kafka cluster, which helps scale the system horizontally. Each broker in the cluster is responsible for managing a portion of the topic's data.

  • Partition: Partition is the division and partition of topics to split data into smaller and manageable chunks. This allows Kafka to parallelize the consumption of messages, which can significantly boost performance. Each partition is an ordered, immutable sequence of messages.

  • Connect: Kafka Connect manages the tasks. The connector is only responsible for generating the set of tasks and indicating to the framework when they need to be updated.

Commonly Used CLI Commands

Start Zookeeper

zookeeper-server-start config\zookeeper.properties
Enter fullscreen mode Exit fullscreen mode

Start Kafka Server

kafka-server-start config\server.properties
Enter fullscreen mode Exit fullscreen mode

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list
Enter fullscreen mode Exit fullscreen mode

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic
Enter fullscreen mode Exit fullscreen mode

Delete a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic mytopic
Enter fullscreen mode Exit fullscreen mode

Consume messages

bin/kafka-console-consumer.sh --new-consumer --bootstrap-server localhost:9092 --topic mytopic --from-beginning
Enter fullscreen mode Exit fullscreen mode

Start Kafka Producer

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
Enter fullscreen mode Exit fullscreen mode

Start Kafka Consumer

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic test
Enter fullscreen mode Exit fullscreen mode

Conclusion

Apache Kafka's real time processing capabilities make it a powerful tool for building data pipelines and stream-processing applications. Whether you are handling log data, monitoring system activity, or building complex event-driven applications, Kafka provides a reliable and efficient solution to stream and process large volumes of data. Understanding Kafka's architecture and core concepts, such as topics, producers, consumers, and partitions, is crucial for leveraging its full potential in modern data-driven applications.

Top comments (0)