Kafka Maven Dependencies
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Most Java applications that use Kafka need fewer Maven dependencies than people expect. For standard producers, consumers, and admin operations, the core artifact is kafka-clients; you add other Kafka artifacts only when you are actually using those APIs.
Start with kafka-clients
The Apache Kafka documentation uses org.apache.kafka:kafka-clients as the main dependency for producer, consumer, and admin code. If your application sends messages, reads topics, or creates topics programmatically, this is the first artifact to add.
Using a property keeps all Kafka artifacts aligned if the project later grows beyond the client library.
A minimal producer with only kafka-clients looks like this:
That single dependency is enough for a large share of Kafka-backed services.
Add kafka-streams Only for Streams Applications
If the application uses the Kafka Streams DSL or Processor API, add kafka-streams as a separate dependency. Do not include it just because the project uses Kafka somewhere else.
That dependency is for topology-building code such as joins, aggregations, state stores, and stream transformations.
If the application never uses this API, keep the dependency list smaller and clearer.
Keep Versions Aligned and Let Frameworks Help
The safest rule is to keep all Kafka artifacts on the same version. Mixing kafka-clients from one release with kafka-streams from another can produce confusing dependency problems.
If you are using a platform such as Spring Boot, check whether the framework already manages Kafka versions. In that case, overriding individual Kafka artifacts casually may create more problems than it solves. The best dependency graph is usually the smallest one that matches the framework's supported version set.
Message Format Libraries Are a Separate Decision
Many dependency questions that sound like "What Kafka dependency do I need?" are really questions about serialization. The Kafka client library gives you core serializers and deserializers for primitive and common Java types. If you need JSON, Avro, or Protobuf, those libraries are added because of the message format, not because Kafka itself requires them.
That distinction matters because it keeps pom.xml understandable. Kafka transport dependencies and data-format dependencies solve different problems and should be chosen independently.
Testing Dependencies Should Stay Focused
For automated tests, resist the urge to add a large pile of Kafka-related libraries just because examples online do. If the goal is to exercise producer or consumer logic, start with the smallest setup that actually gives confidence, such as a targeted integration test against a local broker or test container.
Good dependency hygiene is not only about build speed. It also reduces classpath conflicts and makes upgrades more predictable.
Common Pitfalls
- Adding
kafka-streamsto every Kafka project even when the code only produces or consumes records. - Mixing Kafka artifact versions in the same Maven build.
- Confusing Kafka transport dependencies with separate serializer or schema dependencies.
- Overriding framework-managed Kafka versions without checking the wider dependency graph.
- Treating
pom.xmlsetup as the hard part while ignoring producer configuration, consumer groups, and topic design.
Summary
- Use
kafka-clientsfor standard producer, consumer, and admin code. - Add
kafka-streamsonly when the project actually uses the Streams API. - Keep Kafka artifact versions aligned through one Maven property or framework-managed version.
- Choose serializer libraries separately from Kafka transport libraries.
- Keep the dependency list minimal and justified by the application's real requirements.
Related reading
- Kafka maximum number of connections
- Kafka Memory requirement
- Kafka message codec - compress and decompress
- Kafka message corrupted in master but replica looks good
- Kafka No message seen on console consumer after message sent by Java Producer
- kafka NoClassDefFoundError kafka/Kafka
- Kafka message ordering in partition while producer retry
- Kafka message size with activated compression

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.