A lightweight, high-performance Kafka server implementation in modern C++26. This project implements core Kafka protocol operations with an efficient thread-pool architecture and CRTP-based binary protocol serialization.
| Metric | Value |
|---|---|
| C++ Standard | C++26 |
| CMake | 4.2.3+ |
| License | Apache 2.0 |
CI Status: Build, Tests, Lint, ASan, and Coverage all pass on Linux (GCC 15) and macOS (GCC 15 via Homebrew).
- GCC 15 or later (C++26 support required)
- CMake 4.2.3 or later
- spdlog (optional, for logging)
git clone https://github.com/botirk38/cpp-kafka.git
cd cpp-kafka
cmake -B build -S .
cmake --build ./build
# Run the server (listens on port 9092)
./build/kafka
# Run tests
ctest --test-dir build --output-on-failureOr use the convenience build script:
./your_program.sh- Kafka Protocol Support: API Versions, Describe Topic Partitions, Fetch operations
- High Performance: Thread-pool based concurrent client handling
- Modern C++: Full C++26 features and CRTP patterns
- Efficient Storage: Log-based storage with batch reading
- Clean Architecture: Modular design for easy extension
The codebase follows a clean layered architecture with clear separation of concerns.
Server Layer
- Network I/O, client connection management
- KafkaServer, ThreadPool, SocketFD
Protocol Layer
- Kafka API implementations (API Versions, Describe Topics, Fetch)
- Request parsing and response generation
- Binary serialization (MessageWriter, ByteReader)
Storage Layer
- Topic metadata, partition info
- Log storage and batch reading
- IStorageService interface for abstraction
Common
- Shared utilities and error types
src/
├── server/ Server and networking
│ ├── include/ Public headers
│ ├── tests/ Unit tests
│ └── *.cpp Implementation
├── protocol/ Kafka protocol layer
│ ├── base/ Common protocol types and serialization
│ ├── parser/ Request parsing
│ ├── api_versions/ API Versions implementation
│ ├── describe_topic_partitions/ Describe Topics implementation
│ ├── fetch/ Fetch implementation
│ └── tests/ Protocol tests
├── storage/ Data persistence
│ ├── include/ Public API
│ ├── io/ Binary I/O operations
│ ├── metadata/ Metadata management
│ ├── log/ Log storage
│ ├── internal/ Implementation details
│ └── tests/ Storage tests
| Operation | API Key | Description |
|---|---|---|
| API Versions | 18 | Query supported protocol versions |
| Describe Topic Partitions | 75 | Get topic and partition metadata |
| Fetch | 1 | Retrieve messages from partitions |
- KafkaServer: TCP listener on port 9092, manages client lifecycle
- KafkaParser: Binary protocol message parser
- ThreadPool: Concurrent request handling with worker threads
- MessageWriter / ByteReader: CRTP-based binary serialization with network byte order conversion
- IStorageService: Abstract storage interface for topics, partitions, and messages
cmake -B build -S . \
-DENABLE_COVERAGE=ON # Code coverage instrumentation
-DENABLE_ASAN=ON # AddressSanitizer (memory safety)
-DENABLE_UBSAN=ON # UndefinedBehaviorSanitizer
-DCMAKE_BUILD_TYPE=Releasecmake -B build -S .
cmake --build ./build
ctest --test-dir build --output-on-failure- C++26 is required throughout the project
- All binary protocol data uses network byte order (big-endian)
- Each module has its own
include/directory for public headers - Use relative paths for cross-module includes
- Proper error handling with exceptions
- All code must pass:
- clang-format-18 style checks
- AddressSanitizer checks
- Code coverage instrumentation
- Create headers in
<module>/include/ - Implement in
<module>/directory - Update CMakeLists.txt if adding new files
- Add comprehensive tests
- Ensure no compiler warnings
- Run full CI locally before pushing
All commits trigger GitHub Actions CI:
- Build and test on Ubuntu 22.04 (GCC 15) and macOS (GCC 15 via Homebrew)
- Code formatting check with clang-format-18
- AddressSanitizer to catch memory errors
- Code coverage tracking with lcov
See .github/workflows/ci.yml for details.
See CONTRIBUTING.md for development guidelines and how to contribute.
This project is licensed under Apache License 2.0. See LICENSE for details.
- Kafka Protocol Documentation
- C++26 Reference
- CLAUDE.md - Developer notes and architecture details