A comprehensive Apache Kafka toolkit for Zig with three main components:
Auto-generates type-safe Zig code from Kafka JSON protocol specifications.
Native Zig Kafka client library with Producer, Consumer, and Admin APIs.
librdkafka v2.13.0 compatible shared library for C/C++ applications.
- ✅ Full Protocol Support - Kafka v0-v16 with flexible encoding
- ✅ Zero-Copy Design - Pre-allocated buffers, no runtime allocations
- ✅ Producer API - High-throughput with idempotence support
- ✅ Consumer API - Groups with automatic rebalancing
- ✅ Admin API - Topic and group management
- ✅ C Compatible - Drop-in librdkafka replacement
- ✅ Tested - Kafka 3.8+ and Redpanda 25.3.7
const kafka = @import("kafka");
var client = try kafka.KafkaClient.init(allocator, .{
.bootstrap_servers = &[_][]const u8{"localhost:9092"},
});
defer client.deinit();
var producer = try client.createProducer(.{});
try producer.send(.{
.topic = "test",
.value = "Hello, Kafka!",
});
try producer.flush(5000);#include <rdkafka.h>
rd_kafka_conf_t *conf = rd_kafka_conf_new();
rd_kafka_conf_set(conf, "bootstrap.servers", "localhost:9092", NULL, 0);
rd_kafka_t *rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, NULL, 0);
rd_kafka_topic_t *rkt = rd_kafka_topic_new(rk, "test", NULL);
rd_kafka_produce(rkt, -1, 0, "Hello!", 6, NULL, 0, NULL);
rd_kafka_flush(rk, 5000);git clone https://github.com/yourusername/zig-kafka.git
cd zig-kafka
zig buildOutputs:
zig-out/bin/kafka-protocol-generator- Code generatorzig-out/lib/libkafka.a- Zig static libraryzig-out/lib/librdkafka.dylib- C shared libraryzig-out/include/rdkafka.h- C header
- Protocol Generator - Code generation
- SDK Guide - Native Zig API
- C Compatibility - librdkafka API
- Architecture - System design
zig build test # SDK unit tests
zig build test-integration # Integration (needs Kafka)
zig build test-c # C API tests- Zero-allocation hot paths
- Lock-free concurrency
- 100k+ msgs/sec producer throughput
- Tested against Kafka 3.8 and Redpanda 25.3.7
zig build # Build everything
zig build gen -- <spec> # Run protocol generatorzig build gen -- protocol-gen/specs/ProduceRequest.json output.zig| Feature | Status |
|---|---|
| Producer | ✅ Complete |
| Idempotent Producer | ✅ Complete |
| Consumer | ✅ Complete |
| Consumer Groups | ✅ Complete |
| Admin API | ✅ Complete |
| Transactions | 🚧 In Progress |
| SASL/SSL | 📋 Planned |
✅ Complete | 🚧 In Progress | 📋 Planned
- Zig 0.14.1+
- Kafka 2.0+ or Redpanda 22.3+ (for testing)
Contributions welcome! See CONTRIBUTING.md.
Dual-licensed: Apache 2.0 / MIT
- Apache Kafka Protocol specification
- librdkafka, kafka-go, franz-go projects
- TickStream production Kafka codec
Maintained by: Ben Gamble Status: Active Development - Producer/Consumer APIs production-ready