Kafka cluster
Single broker
Data management
System architecture
Distributed systems

Kafka cluster with single broker

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. Initially conceived as a messaging queue, Kafka is based on an abstraction of a distributed commit log. Since being created and open sourced by LinkedIn in 2011, Kafka has quickly evolved from messaging queue to a full-fledged event streaming platform.

Configuration of a Single Broker Kafka Cluster

While Kafka is meant to be run in a cluster with multiple brokers, it is entirely possible to set up a single broker Kafka cluster. This setup is typically used for development, testing, or in environments where redundancy and high availability are not crucial requirements.

A single broker Kafka cluster simplifies the configuration and reduces the operational overhead. Here's how to set up a Kafka broker:

  1. Installation: Download the latest Kafka release and extract it.
  2. Configuration:
    • Navigate to the Kafka config directory.
    • Edit the server.properties file.
      • Assign a unique ID to the broker with the broker.id setting.
      • Set the listeners to specify the hostname and port (e.g., PLAINTEXT://your.host.name:9092).
      • Adjust the log directories log.dirs to define where to store Kafka logs.
  3. Start the Broker:
    • Use the Kafka script to start the server: bin/kafka-server-start.sh config/server.properties
  4. Create a Topic:
    • To publish and subscribe to messages, you need a topic, which can be created using: bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1
  5. Testing the Setup:
    • Produce some messages: bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092
    • Consume the messages: bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092

Kafka Cluster with Single Broker Architecture

Here are the essential components of Kafka:

  • Broker: Handles all requests from producers and consumers and stores data on disk.
  • ZooKeeper: Manages brokers and deals with distributed coordination (used pre Kafka 2.8).
  • Topic: Categorized feed of records.
  • Partition: Topics are split into partitions for parallel processing.
  • Replicas: Copies of a partition.

In a single broker setup, all parts of the Kafka functions (topics, partitions) are contained within one machine. This means no redundancy for partitions (replication-factor is 1).

Table: Key Configuration Properties

PropertyDescriptionTypical Value
broker.idUnique identifier for the broker in the cluster0 for single broker setups
listenersHostname and port Kafka binds to for network requestsPLAINTEXT://your.host.name:9092
log.dirsDirectory where Kafka will store log files/var/lib/kafka
zookeeper.connectZooKeeper connection string (not needed for KRaft mode)localhost:2181

Considerations for a Single Broker Setup

A single broker Kafka cluster has several limitations:

  • Fault Tolerance: There is no redundancy. If the broker goes down, the service becomes unavailable.
  • Scalability: Limited to the resources of a single machine. Cannot distribute the load or store more data than the machine can handle.
  • Data safety: No replicas mean if the data is corrupted or lost on the broker, recovery is not possible.

Additional Subtopics

  • Monitoring and Maintenance: Using tools like JMX exporter and Prometheus to monitor Kafka metrics.
  • Advanced Configurations: Tuning performance through configurations like num.network.threads or num.io.threads.
  • Security: Setting up security protocols (SSL/TLS, SASL/PLAIN).

In conclusion, while a single broker Kafka setup can be useful for development or small, non-critical applications, it lacks the benefits of a distributed system. Implementing multiple brokers provides redundancy, scalability, and improved performance, which are critical for most production environments.


Course illustration
Course illustration

All Rights Reserved.