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:
- Installation: Download the latest Kafka release and extract it.
- Configuration:
- Navigate to the Kafka config directory.
- Edit the
server.propertiesfile.- Assign a unique ID to the broker with the
broker.idsetting. - Set the
listenersto specify the hostname and port (e.g.,PLAINTEXT://your.host.name:9092). - Adjust the log directories
log.dirsto define where to store Kafka logs.
- Start the Broker:
- Use the Kafka script to start the server:
bin/kafka-server-start.sh config/server.properties
- 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
- 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
| Property | Description | Typical Value |
broker.id | Unique identifier for the broker in the cluster | 0 for single broker setups |
listeners | Hostname and port Kafka binds to for network requests | PLAINTEXT://your.host.name:9092 |
log.dirs | Directory where Kafka will store log files | /var/lib/kafka |
zookeeper.connect | ZooKeeper 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.threadsornum.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.

