Using Agentic AI to create the next generation of non-Java Kafka clients Confluent engineers reported that agentic AI tooling can generate a family of open-source non-Java Apache Kafka clients directly from the Apache Kafka Java client source, but only with substantial engineer effort to get the right result. The company said Confluent Cloud handles almost as many connections from non-Java clients as from Java clients, and that its existing non-Java clients built on Magnus Edenhill's librdkafka have lagged Apache Kafka, which ships over 20 new KIPs per release from more than 100 active contributors. The goal is a modern asynchronous core with sustained feature parity, consistent configuration and behavior with the Java client, and more idiomatic APIs across languages. Blog Home https://developer.confluent.io/blog/ Using Agentic AI to create the next generation of non-Java Kafka clients Could AI tools help us generate a family of open-source non-Java clients directly from the Apache Kafka® source? As I will explain, our experience suggests that they can - but only with a lot of work by engineers to get the right result. Apache Kafka applications are written in many languages, but the Apache Kafka project itself provides only a Java client https://kafka.apache.org/44/javadoc/index.html . The Apache Kafka project is moving fast with significant innovation constantly being delivered by more than 100 active contributors. Each Kafka release typically has over 20 new KIPs, many of which touch the clients. A significant proportion of Kafka applications are not written in Java. In fact, Confluent Cloud - a managed Apache Kafka service - handles almost as many connections from non-Java clients across a variety of languages as it handles from Java clients. Confluent's non-Java clients are built on top of a C library originally written by Magnus Edenhill called librdkafka https://github.com/confluentinc/librdkafka , which is almost as old as Kafka itself. Client support for other languages such as Python and JavaScript is then layered on top of this C language core. This has served the community well for over a decade. There are Kafka clients from other groups too, some of which are built on librdkafka. The difficulty is keeping the clients up to date and, historically, support for other languages has lagged behind. The Apache Kafka client and librdkafka differ architecturally, including in threading, memory management, batching and buffering. Those differences matter when tuning applications. Advice for a Java client sending data to a topic with many partitions over high-latency connections cannot simply be applied to a JavaScript client built on librdkafka. Because librdkafka is an entirely separate codebase, when a new feature arrives in Apache Kafka, it takes time before it is available in librdkafka. Some features never arrive at all. Keeping up with the increasingly rapid pace of Apache Kafka contributions required a new approach. The big idea The big idea is to derive non-Java clients directly from the Apache Kafka Java client with the assistance of AI tooling. We want: - A modern, asynchronous core which can be used to build great clients for other languages - Complete, sustained feature parity with Apache Kafka across all languages - Consistent configuration and behaviour compared with the Java client - More idiomatic APIs in all languages - Great performance and efficiency That’s quite a list. Apache Kafka defines its programming interface in Java. Python, JavaScript and golang are very different languages, from Java and from each other. Concepts in Java such as inheritance and try-catch exception handling don't necessarily have direct equivalents in the other languages. The central design challenge is to create natural programming interfaces for the other languages which preserve correspondence with Kafka’s Java interface without forcing the other languages to look like Java. Instead, we need a set of rules mapping Java into the other languages so that they remain compatible as the Java client evolves. Looking at Confluent's existing non-Java clients, we realised that it was necessary to evolve their interfaces too. They were created before this approach to mapping between languages was considered. The mapping rules must therefore handle not just today’s Java features, but features that have not yet been designed: the interfaces need room to grow naturally as those new features arrive. Here’s a trivial example in Python. In the librdkafka-based confluent-kafka-python, a consuming application receives a single Message or None from each call to Consumer.poll timeout , and on each message, it must check whether an error occurred like this: try: consumer.subscribe topics while running: msg = consumer.poll timeout=1.0 if msg is None: continue if msg.error : raise KafkaException msg.error else: msg process msg finally: consumer.close This doesn’t match the Kafka Java client at all well, because in Java KafkaConsumer.poll Duration returns ConsumerRecords and it throws KafkaException for errors. As a result, we need to change the Python interface to have a similar shape which looks like this: try: consumer.subscribe topics=topics while running: records = consumer.poll timeout=1.0 for r in records: msg process r finally: consumer.close Why does this change matter? Apache Kafka enhanced ConsumerRecords to improve offset tracking, and we want Python and the other languages to benefit from that enhancement. The code snippet shows why correspondence with the Java interface matters: it leaves room to carry the same improvements into other languages. Deriving the clients from Java is our approach to maintaining that link. Looking at the huge strides which have been made in AI coding tools recently, we wanted to see whether we could perform translation from Java to create a new core for the derived clients, building a replacement for librdkafka which we could keep up to date with Apache Kafka more easily. The code would remain owned by the engineers, but their productivity would be magnified through the use of AI. What we had in mind was a project with two distinct phases: 1. Translate the entire Java client at a known point 2. Continuously apply commits from Apache Kafka trunk to the translated codebase To evaluate the approach, we decided to focus on the first of these phases. We chose Rust as the target language and ran an engineering spike: a focused experiment to find out whether the translation approach was worth pursuing. Engineering spike There are two tricks with an engineering spike. First, attempt something bold and adventurous or you don’t need a spike at all. Second, be prepared to fail fast if you discover that it’s all just a massive waste of time. The Apache Kafka client is a large, complicated, multi-threaded piece of Java code. It would take several weeks and a huge pile of tokens to translate its entirety into Rust. We decided that we didn’t need to translate it all to start to get some answers. We started with enough of the producer and consumer to give some meaningful performance numbers and skipped a lot of features we didn’t need to start with, such as transactions. We were fairly new to using agent-based software development, although we did have experience of using AI for analysis and coding tasks. We brought a lot of experience of the Apache Kafka codebase, librdkafka and the existing non-Java clients, and we developed our knowledge of Rust across the team as the spike progressed. We started with Anthropic Claude® Opus 4.6, but as an indication of how fast this stuff moves, we upgraded several times as the new releases came out. The spike ran for nearly three months, with two engineers each spending about 75% of their time on it. We organised the work into two-week sprints, each with a target and an end-of-sprint review of progress and results. Initially, the AI needed hands-on guidance: the agents asked many clarifying questions, some requiring research before we could answer properly. We also had to manage expectations. Even with AI, this work took time. After two weeks, we had a working Kafka producer in Rust using insecure connections. After two more, the producer supported TLS and authentication. And after two more, we also had a basic consumer working. There was a big list of restrictions, but it was possible to get some comparative performance measurements at this point. We had also started to get an idea of the kind of things that the AI had got wrong. Sometimes, it made mistakes. Sometimes, the instructions were insufficient to get the desired outcome. We even threw away the initial translation after a few weeks and tried again with tighter instructions. This proved to be very worthwhile. After three months, the performance measurements gave us confidence that a Rust core would be fast and efficient enough to do the job. We had almost complete producer and consumer code in Rust and had tested it across a wide range of workloads. There were still rough edges, but the results were promising. To reach a decision on whether to proceed, we also evaluated other dimensions such as maintainability, extensibility and compatibility with the Java client interface. As a proof of concept, we did a little work building a Python client on top of the Rust core, but there was a lot more work required here. The spike answered a feasibility question. It gave us confidence to proceed with the Rust core, while the derived clients still needed substantial work. Keeping the translated codebase aligned with future Apache Kafka commits remained as future work. The results were convincing and we made the decision to start the project to create the translated clients for real. The translation process A common technique that people use with AI coding tools is known as “adversarial agents”. You divide the work between agents which write the code, and agents which evaluate the code. Our agents are called the Actor and the Critic, and there is also the Project Manager which orchestrates the other agents. You can see the prompts that we use for each agent type https://github.com/confluentinc/kafka-clients/tree/master/.claude/agents , and the detailed translation rules https://github.com/confluentinc/kafka-clients/tree/master/.claude/rules . The rules have evolved https://github.com/confluentinc/kafka-clients/commits/master/.claude/rules significantly as the project has progressed. It is slightly comical how the agent instructions everyone writes always start with a sentence like “You are an elite ...”. I have no idea whether the flattery helps, but everyone does it. The translation progresses in a three-level hierarchy: Milestones, divided into Phases, which may be divided into Layers. The Project Manager agent makes different choices about how to structure each milestone. Each translation milestone starts with a prompt, such as: The Producer should be able to accumulate messages into batches to produce in a Produce RPC. Dependencies determine the order of the work. The first milestone translates the leaves of the code’s dependency tree - the classes with no other dependencies — and later milestones build on the translated code they need. Milestones that share dependencies but do not depend on each other can run in parallel. Translation does not begin until a human has approved the milestone plan. The Project Manager agent prepares that plan by analysing the requirements, identifying the classes to translate and their dependencies, and checking what already exists. Where the plan involves design choices, it asks for guidance. Java threads and Tokio tasks, for example, are not exact equivalents, so a human must guide the mapping. Where we already know the required approach, we give the agent detailed instructions rather than leave the design choice open. Milestone approval is followed by a second planning step. The Project Manager agent creates a plan for each phase, and a human approves those phase plans too. Translation begins only after the relevant phase plan has been approved. The Project Manager agent starts the Actor and Critic agents and gives them the instructions. The Actor and Critic agents communicate via git and take turns to run. First, the Actor agent performs the translation tasks, makes sure the code builds cleanly, and passes the linter and the tests. It summarises what it did and commits the changes to git. Next, the Critic agent evaluates the changes and creates a file containing its review comments and commits that to git. The Actor agent then reads the Critic agent’s comments, resolves them, records the resolutions in a file and commits the changes to git. The two agents repeat this review-and-fix cycle until the Critic agent has no further comments. The loop typically runs about 5 iterations, sometimes more, sometimes less. At the end of each phase, the Project Manager agent updates the status, copies the history of what the agents did, and starts the next phase if there is one. If you’re interested in the detail of the actual milestones, you can see the history https://github.com/confluentinc/kafka-clients/tree/master/design/history . Some things we learnt along the way While Apache Kafka has a lot of tests, they are a very long way from being a specification of every aspect of the required behaviour. When translating the Kafka code, we also translated the tests. Just because the translated tests passed did not mean the translated code behaved sensibly. For example, while we got working code extremely quickly, the initial performance runs were very slow. When we investigated, we found a sleep on every iteration of the networking loop. The translated tests passed despite that choice. Performance testing exposed a problem that those tests did not catch. The Java client is multi-threaded and in some cases shares data between threads. We used Tokio tasks instead of threads, but they’re not exactly the same, so we needed more detailed instructions to get the correct effect. Now future translation in that area benefits from the additional guidance. These learnings changed how we approached the translation. We needed instructions that explained the intended behaviour, not just the source code to translate, and checks that went beyond passing translated tests. Throwing away the initial translation and starting again with better instructions was worthwhile because a better translation had fewer issues to resolve. When we moved from Apache Kafka 4.3.1 to 4.4.0, we decided to apply the changes which had been made to Kafka to our translated code, rather than translate everything again. It took less than 2 working days to apply 191 commits which represent several months' changes. The most important lesson is that the quality and specificity of the instructions has a very strong bearing on the quality of the output. We didn't really test variations of the translation rules as such, but we did refine them as it became clear which details we needed to include to get what we wanted. The Rust client interface While the AI was great at generating the translated code, the design of the Rust client interface was an area where the humans took over. Designing the Rust interface took several iterations of experimentation and discussions with Rust experts. A direct mapping from Java was not enough: Java has inheritance, polymorphism, exceptions and threads, while Rust prioritises performance and memory safety. Those differences shaped the interface we developed. It may still benefit from further refinement as more people try it out. At a superficial level, there is quite a close resemblance between simple Kafka applications in Java and Rust as a result of the translated naming. For example, here’s a snippet of a Rust producer that connects to a cluster and sends a record to a topic. js let props = HashMap::from "bootstrap.servers".to string , "localhost:9092".to string , ; let config = ProducerConfig::new &props ?; let producer = KafkaProducer::