Setting up Apache Kafka for developer/integration test environment
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 powerful 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. Setting it up for a developer or integration test environment involves a series of steps that ensure it mimics as closely as possible the behavior of a production system without the associated overhead.
Prerequisites
Before setting up Apache Kafka, ensure you have the following prerequisites installed:
- Java 8 or higher: Kafka is written in Java, so Java is required to run it.
- Zookeeper: Kafka uses Zookeeper for managing and coordinating Kafka brokers.
- Apache Kafka: Download the latest version of Kafka from https://kafka.apache.org/downloads.
Step-by-Step Setup Procedure
Step 1: Install Zookeeper
First, install Zookeeper or use a Docker image. If installing manually:
This will start Zookeeper on the default port (2181).
Step 2: Install Apache Kafka
After downloading Kafka, extract it and use the provided scripts to start the Kafka server.
Step 3: Create a Kafka Topic
Create a topic where you can send and receive messages.
Here, replication-factor 1 and partitions 1 are typically enough for most development environments.
Step 4: Test Producer and Consumer
To ensure Kafka is running correctly, test producing and consuming messages:
Docker Alternative
For easier setup and teardown, use Docker. You can run Kafka and Zookeeper using docker-compose:
Run it using:
Key Configurations
Configuration parameters in the server.properties and zoo.cfg files play a crucial role. Here are some important settings:
| Configuration Key | Description | Recommended Value for Dev |
num.network.threads | Threads for network processing | 3 |
num.io.threads | I/O threads (per disk/controller) | 8 |
socket.send.buffer.bytes | Send buffer (SO_SNDBUF socket option) | 102400 |
socket.receive.buffer.bytes | Receive buffer (SO_RCVBUF socket) | 102400 |
log.dirs | Directories where logs are stored | /tmp/kafka-logs |
Additional Considerations
- Data persistence: In production, consider the data retention policy. In a test environment, using
/tmpas log storage with a cleanup policy might be sufficient. - Security: Setup is without security parameters such as SSL or SASL for simplicity, important in production setups.
- Monitoring: Consider implementing monitoring tools like JMX exporter for Prometheus to track Kafka’s performance even in development.
Conclusion
Setting up Apache Kafka for a development or integration testing environment provides a robust platform for developing streaming applications. By following the setup steps and configurations discussed, developers can create a functional environment that allows for the development and testing of Kafka-based applications before deployment to production.
Related reading
- Setup RabbitMQ consumer in ASP.NET Core application
- Sharing resources between workers in a message queue setup
- Should I use Celery or Carrot for a Django project?
- Should we use max.poll.records or max.poll.interval.ms to handle records that take longer to process in kafka consumer?
- Setting up JMeter for Distributed testing in AWS with connectivity issues
- Settings variable values in a Moq Callback call
- Shutdown Error in RabbitMq sasl Log
- Shutting down Kafka Consumer

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.