kafka cluster configuration
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed 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 open-sourced by LinkedIn in 2011, Kafka has rapidly evolved into a full-fledged event streaming platform.
Kafka Cluster Architecture
A typical Kafka cluster consists of multiple brokers, which are servers that store data and serve clients. To ensure high availability and fault tolerance, data in Kafka is replicated across multiple brokers.
Key Components:
- Brokers: Nodes in the Kafka cluster that handle storage and I/O for messages.
- ZooKeeper: Manages and coordinates Kafka brokers. It is responsible for leader election of partitions and helps in cluster management.
- Producers: Clients that publish messages to Kafka topics.
- Consumers: Clients that subscribe to topics and process the feed of published messages.
- Topics: Categories or feeds to which messages are published. Topics are split into partitions for scalability and parallel processing.
Brokers and Cluster Expansion
Kafka brokers are stateless, so you can scale the cluster by simply adding more brokers and rebalancing the partitions across the available brokers without downtime. Each broker handles data for a subset of partitions from various topics.
Configuration Details
Configuring a Kafka cluster involves tuning several performance, reliability, and resource utilization parameters. Here’s how you can configure a standard Kafka setup:
server.properties
This file contains configuration settings specific to each broker.
Key parameters include:
broker.id: Unique ID for each broker in the cluster.listeners: Addresses (host/IP, port) the broker will listen on.num.network.threads: The number of threads handling network requests.num.io.threads: The number of threads doing I/O operations.socket.send.buffer.bytesandsocket.receive.buffer.bytes: TCP socket buffer sizes.log.dirs: Directories where the logs (data) are stored.num.partitions: Default number of log partitions per topic.
zookeeper.properties
ZooKeeper's configuration, which is crucial for managing the cluster state of Kafka:
clientPort: Port to listen for client connections.dataDir: Directory where ZooKeeper's data is stored.maxClientCnxns: Limits the number of concurrent connections that a single client can make to a single member of the ZooKeeper ensemble.
Kafka Reliability and Fault Tolerance
Kafka ensures data reliability and fault tolerance through:
- Replication: Topics can be configured to replicate across multiple brokers. If one broker fails, another can serve the data.
- Acknowledgments: Producers can configure the level of acknowledgment they require from brokers:
acks=0: Producer will not wait for an acknowledgment.acks=1: Only the leader broker acknowledges the write.acks=all: All replicas acknowledge the write.
Here’s a summarized table with some common configurations and their implications:
| Configuration Parameter | Description | Common Values |
broker.id | Unique identifier for each broker in the cluster | Integer (e.g., 0, 1, 2) |
num.network.threads | Handles network requests | 3 |
num.io.threads | Handles disk I/O requests | 8 |
log.dirs | Directory where logs are stored | /var/lib/kafka/data |
num.partitions | Default partitions per topic | 3 |
zookeeper.connect | ZooKeeper service connect string | localhost:2181 |
acks | Producer acknowledgment level | 0, 1, all |
compression.type | Compression type for data storage | none, gzip, snappy, lz4, zstd |
Performance Considerations
Configuring Kafka for optimal performance involves understanding the workload and the resources available:
- Memory and Disk: Make sure the server has enough RAM and fast disks (preferably SSDs).
- Network: Network throughput can be a bottleneck, make sure the network configuration is capable of handling the anticipated traffic.
- Partition Count: More partitions allow greater parallelism but increase overhead.
- Replication Factor: Higher replication ensures better fault tolerance but requires more disk space and network usage.
Kafka's design allows it to function as the central "nervous system" for large-scale data processing environments. Correct configuration and tuning are key to leveraging its full potential and achieving high throughput and low latency data processing.
Related reading
- Kafka cluster loses or duplicates messages
- Kafka cluster with single broker
- Kafka command line producer/consumer have 1 second latency
- kafka Commit offsets failed with retriable exception. You should retry committing offsets
- Kafka Compaction for topic
- Kafka Connect - do the workers need direct communication with each other
- kafka connect hdfs sink connector is failing even when json data contains schema and payload field
- Kafka connect HDFS sink ERROR failed creating a WAL

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.