Confluent Rewrites Kafka Client in Rust with AI
Contents
Apache Kafka officially maintains only a Java client, even though non-Java workloads account for nearly half of the connections in Confluent Cloud. Other languages have historically relied on librdkafka, which handles threading and memory allocation differently than the Java core. To close that gap, Confluent set out to rewrite the client in Rust using AI coding agents.
Why the Team Scrapped the First Build
Two staff engineers spent about 75 percent of their time on the project. Using Anthropic's Claude models, the agents built a working Rust producer in two weeks. By week four, TLS and authentication worked, and a basic consumer ran by week six. Still, the team decided to throw out the entire codebase and start over with clearer architectural rules.
The generated code passed the translated Java unit tests, but profiling showed a major issue: the network event loop was running a sleep call on every pass. The unit tests passed because the logic ran fine at low volume, but throughput collapsed under load. The team realized prompt instructions needed to describe system behavior rather than just translate syntax.
A Three-Agent Workflow with Human Review
To avoid similar issues, Confluent replaced one-off prompts with a multi-agent setup consisting of a Project Manager, an Actor, and a Critic:
- Project Manager: Organizes milestones and coordinates tasks between the Actor and Critic.
- Actor and Critic: Work through Git. The Actor commits converted code, and the Critic reviews the diffs for bugs and unidiomatic Rust. Most reviews take about five passes.
- Human Review: Engineers review major design choices, like mapping Java threads to asynchronous Tokio tasks.
Project Manager --> Actor (Code Generation)
|
v (Git Commit)
Critic (Static Analysis & Review)
|
v (~5 Iterations)
Human Engineers (Tokio Tasks & FFI Verification)Handling Upstream Updates
When Apache Kafka 4.4.0 came out, the team tested the new process by pulling in 191 upstream commits. Those commits represented several months of work on the Java codebase, but porting them into the Rust client took less than two days.
Generating the code went quickly, but adapting it to work cleanly across multiple runtimes took careful engineering.
Confluent released the Rust client under the Apache License 2.0, along with an early preview of a Python client built on top of it. The team plans to turn the translation workflow into a fully automated continuous integration pipeline by 2027.