Starting Kafka Server Permanently
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If by "start Kafka permanently" you mean "keep it running after logout, restart it on failure, and bring it up automatically after reboot," the right answer is to run Kafka under a service manager such as systemd. Starting it in a shell with kafka-server-start.sh is fine for experiments, but it is not a production operating model.
Modern Kafka deployments also need one clarification up front: current Kafka versions support KRaft mode, which removes the ZooKeeper dependency. Older guides that start ZooKeeper first are describing older deployments.
Local Start Versus Permanent Service
For a quick local run, you can still start Kafka directly:
That keeps Kafka attached to the current shell. Close the session and the broker stops. Even -daemon is only a lightweight backgrounding trick, not a robust service-management solution.
For a permanent setup, you want:
- automatic startup on boot
- restart after failure
- centralized logs
- a dedicated service user
That is exactly what systemd is for on most Linux systems.
Use a Dedicated Kafka User
Do not run Kafka as root. Create a dedicated account and make sure the data and log directories belong to it:
Using a dedicated service user limits blast radius and makes ownership simpler.
A Practical systemd Service
A minimal service file looks like this:
Save that as /etc/systemd/system/kafka.service, then load and enable it:
Now Kafka starts at boot and restarts if the process exits unexpectedly.
KRaft Versus ZooKeeper
This is the part many outdated guides miss. In newer Kafka deployments, KRaft is the default architecture and you do not separately run ZooKeeper. Your broker configuration needs the right KRaft settings and formatted storage before first startup.
For older ZooKeeper-based clusters, you still need the metadata service running before the broker. If you are inheriting an existing installation, check the configuration files before copying instructions from a random guide.
The operational lesson is simple: know which architecture you are running before you automate the service.
Check Service Health the Right Way
Once the service is installed, use systemctl and journalctl instead of guessing:
Kafka's own scripts also help confirm the broker is really usable:
That is better than assuming the process is healthy just because a PID exists.
Environment and Limits Matter
Kafka is sensitive to JVM settings, disk paths, and file descriptor limits. A service file is a good place to make those assumptions explicit.
For example:
Those values depend on the workload, but the general principle is correct: production services should not rely on whatever random shell environment happened to start them.
Containers and Orchestration
If Kafka runs in Docker, Kubernetes, or another orchestrator, that platform replaces systemd as the service manager. The same goals still apply:
- automatic restart
- declarative startup
- health checking
- clear log collection
So the exact tool changes, but the pattern does not.
Common Pitfalls
The most common mistake is assuming nohup or -daemon is equivalent to a proper service. It is not. Those approaches do not give you the same restart semantics, observability, or startup management.
Another common issue is following ZooKeeper-based instructions on a KRaft deployment, or the reverse. Kafka setup has changed materially across versions.
People also run Kafka as root, which is unnecessary and risky. Use a dedicated service account.
Finally, do not declare the service done after systemctl start. Verify that the broker actually accepts client connections and that the data directories and listeners are configured correctly.
Summary
- For a permanent Kafka server on Linux, prefer
systemdover shell backgrounding tricks. - Use a dedicated
kafkaservice account and explicit data and log directories. - Modern Kafka often runs in KRaft mode, so ZooKeeper instructions may be outdated.
- Enable restart-on-failure and verify health with
systemctl,journalctl, and Kafka CLI tools. - The goal is not just "process stays up," but "broker starts predictably, survives failure, and is operable."
Related reading
- Stateful and Stateless consumer on Kafka
- Stop a Kafka Streams app
- stopping spark streaming after reading first batch of data
- Stopping/Purging Periodic Tasks in Django-Celery
- Static outgoing IP in Kubernetes
- Static outgoing IP in Kubernetes
- Store images in Apache Kafka?
- Store your events directly from kafka into database?, when or why using S3/HDFS before?

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.