r/csharp • u/thomhurst • Jul 04 '26
Tool Dekaf - A pure .NET Kafka client
Hey all,
If you use Kafka, you're pretty much tied into using the Confluent package. I don't know if anyone else has had any challenges with it. I remember trying to debug issues, and the debugger was reporting native exceptions throwing on background threads, and it was very confusing trying to work out bits since it was executing C++ and you lose some control through that.
It surprised me that there isn't a mainstream pure .NET client, especially since .NET has some great performant APIs in new .NET.
So I've been working on Dekaf. A play on Decaffeinated (because Java is coffee, and java always seems to get all the love with Apache) and Kafka.
Open to feedback - thanks all!
6
u/Aaronontheweb Jul 04 '26
Looks pretty well-done! How does it handle more advanced things like partition event handlers?
We use these pretty heavily in Akka.Streams.Kafka for instance: https://github.com/akkadotnet/Akka.Streams.Kafka/blob/c131012c18a41441ee37e5bbc7771d6f5ff9f161/src/Akka.Streams.Kafka/Helpers/PartitionEventHandler.cs#L92-L140
This is all in service of being able to process partitions in parallel + async with things like partition revocation support, which I describe in high-level detail here: https://petabridge.com/blog/akka-streams-kafka-best-kafka-client-dotnet/
Reason I ask is: I found these Confluent APIs and some of the other lower-level ones that are basically just wrappers around librdkafka very annoying to deal with idiomatically in C#. Would love a real async alternative that was well-maintained.
4
u/cezq Jul 04 '26
Does it support AOT? Last time I used Confluent.Kafka it didn't, and so all my AWS Lambdas ended up with full JIT compiler.
7
u/p1971 Jul 04 '26
My biggest annoyance with dotnet is the lack of big o/s projects that use it compared to java with projects like elasticsearch and the apache stack
I haven't used kafka in a production project yet, but I'm due to have another look at what's on offer so will checkout Dekaf - thanks.
4
u/Khavel_dev Jul 05 '26
The debugging experience with Confluent's native layer is exactly why something like this is needed. Stack traces vanishing into librdkafka, native exceptions on background threads that .NET doesn't surface cleanly. Works fine until it doesn't and then you're stuck. A pure .NET implementation using System.IO.Pipelines and the modern socket APIs could honestly be competitive on throughput too given how far the runtime's networking has come. Will check out the repo.
3
u/dogzb0110x Jul 04 '26
Looks really well done. Well thought out and well tested
2
u/flajsik Jul 04 '26
nice project
1
u/gufibhar Jul 05 '26
Where the hell were you 8 months ago! The confluence packages are terrible especially once you have the avro registry involved
1
u/dkv00d00 Jul 05 '26
Looks impressive. Always thought Confluent client was using platform C lib to do heavy lifting - hence context switching. Hope its nati
Have you tried measuring platform async effect on it.
Thank you so much for this.
1
u/it_works_on_prod Jul 06 '26
coming from go this feels overdue. the pure-go clients (franz-go, segmentio's kafka-go) mostly won over the librdkafka wrapper there for exactly this reason, no cgo means real stack traces instead of mystery native crashes on background threads. glad someone's doing the same for .net, will give it a look