| Crates.io | rafka-rs |
| lib.rs | rafka-rs |
| version | 0.1.0 |
| created_at | 2025-10-25 21:53:24.509779+00 |
| updated_at | 2025-10-25 21:53:24.509779+00 |
| description | Rafka - A high-performance distributed message broker written in Rust |
| homepage | https://github.com/Mahir101/Rafka |
| repository | https://github.com/Mahir101/Rafka |
| max_upload_size | |
| id | 1900709 |
| size | 123,386 |
A High-Performance Distributed Message Broker Built in Rust
Rafka is a blazing-fast, experimental distributed asynchronous message broker inspired by Apache Kafka. Built with Rust and leveraging Tokio's async runtime, it delivers exceptional performance through its peer-to-peer mesh architecture and custom in-memory database for unparalleled scalability and low-latency message processing.
graph TB
subgraph "Client Layer"
P[Producer]
C[Consumer]
end
subgraph "Broker Cluster"
B1[Broker 1<br/>Partition 0]
B2[Broker 2<br/>Partition 1]
B3[Broker 3<br/>Partition 2]
end
subgraph "Storage Layer"
S1[In-Memory DB<br/>Partition 0]
S2[In-Memory DB<br/>Partition 1]
S3[In-Memory DB<br/>Partition 2]
end
P -->|gRPC Publish| B1
P -->|gRPC Publish| B2
P -->|gRPC Publish| B3
B1 -->|Store Messages| S1
B2 -->|Store Messages| S2
B3 -->|Store Messages| S3
C -->|gRPC Consume| B1
C -->|gRPC Consume| B2
C -->|gRPC Consume| B3
B1 -->|Broadcast Stream| C
B2 -->|Broadcast Stream| C
B3 -->|Broadcast Stream| C
sequenceDiagram
participant P as Producer
participant B as Broker
participant S as Storage
participant C as Consumer
P->>B: PublishRequest(topic, key, payload)
B->>B: Hash key for partition
B->>B: Check partition ownership
B->>S: Store message with offset
S-->>B: Return offset
B->>B: Broadcast to subscribers
B-->>P: PublishResponse(message_id, offset)
C->>B: ConsumeRequest(topic)
B->>B: Create broadcast stream
B-->>C: ConsumeResponse stream
loop Message Processing
B->>C: ConsumeResponse(message)
C->>B: AcknowledgeRequest(message_id)
C->>B: UpdateOffsetRequest(offset)
end
rafka/
โโโ Cargo.toml # Workspace manifest
โโโ config/
โ โโโ config.yml # Configuration file
โโโ scripts/ # Demo and utility scripts
โ โโโ helloworld.sh # Basic producer-consumer demo
โ โโโ partitioned_demo.sh # Multi-broker partitioning demo
โ โโโ retention_demo.sh # Message retention demo
โ โโโ offset_tracking_demo.sh # Consumer offset tracking demo
โ โโโ kill.sh # Process cleanup script
โโโ src/
โ โโโ bin/ # Executable binaries
โ โโโ start_broker.rs # Broker server
โ โโโ start_producer.rs # Producer client
โ โโโ start_consumer.rs # Consumer client
โ โโโ check_metrics.rs # Metrics monitoring
โโโ crates/ # Core library crates
โ โโโ core/ # Core types and gRPC definitions
โ โ โโโ src/
โ โ โ โโโ lib.rs
โ โ โ โโโ message.rs # Message structures
โ โ โ โโโ proto/
โ โ โ โโโ rafka.proto # gRPC service definitions
โ โ โโโ build.rs # Protocol buffer compilation
โ โโโ broker/ # Broker implementation
โ โ โโโ src/
โ โ โโโ lib.rs
โ โ โโโ broker.rs # Core broker logic
โ โโโ producer/ # Producer implementation
โ โ โโโ src/
โ โ โโโ lib.rs
โ โ โโโ producer.rs # Producer client
โ โโโ consumer/ # Consumer implementation
โ โ โโโ src/
โ โ โโโ lib.rs
โ โ โโโ consumer.rs # Consumer client
โ โโโ storage/ # Storage engine
โ โโโ src/
โ โโโ lib.rs
โ โโโ db.rs # In-memory database
โโโ docs/
โ โโโ getting_started.md # Getting started guide
โโโ tasks/
โ โโโ Roadmap.md # Development roadmap
โโโ Dockerfile # Container configuration
โโโ LICENSE # MIT License
git clone https://github.com/yourusername/rafka.git
cd rafka
cargo build --release
./scripts/helloworld.sh
cargo run --bin start_broker -- --port 50051 --partition 0 --total-partitions 3
cargo run --bin start_consumer -- --port 50051
cargo run --bin start_producer -- --message "Hello, Rafka!" --key "test-key"
The broker can be configured via command-line arguments:
cargo run --bin start_broker -- \
--port 50051 \
--partition 0 \
--total-partitions 3 \
--retention-seconds 604800
Available Options:
--port: Broker listening port (default: 50051)--partition: Partition ID for this broker (default: 0)--total-partitions: Total number of partitions (default: 1)--retention-seconds: Message retention time in seconds (default: 7 days)Edit config/config.yml for persistent settings:
server:
host: "127.0.0.1"
port: 9092
log:
level: "info" # debug, info, warn, error
broker:
replication_factor: 3
default_topic_partitions: 1
storage:
type: "in_memory"
rafka-core)Purpose: Defines fundamental types and gRPC service contracts.
Key Components:
Message, MessageAck, BenchmarkMetricsKey Files:
message.rs: Core message types and acknowledgment structuresproto/rafka.proto: gRPC service definitionsrafka-broker)Purpose: Central message routing and coordination service.
Key Features:
Key Operations:
publish(): Accept messages from producersconsume(): Stream messages to consumerssubscribe(): Register consumer subscriptionsacknowledge(): Process message acknowledgmentsupdate_offset(): Track consumer progressrafka-producer)Purpose: Client library for publishing messages to brokers.
Key Features:
Usage Example:
let mut producer = Producer::new("127.0.0.1:50051").await?;
producer.publish("my-topic".to_string(), "Hello World".to_string(), "key-1".to_string()).await?;
rafka-consumer)Purpose: Client library for consuming messages from brokers.
Key Features:
Usage Example:
let mut consumer = Consumer::new("127.0.0.1:50051").await?;
consumer.subscribe("my-topic".to_string()).await?;
let mut rx = consumer.consume("my-topic".to_string()).await?;
while let Some(message) = rx.recv().await {
println!("Received: {}", message);
}
rafka-storage)Purpose: High-performance in-memory storage engine.
Key Features:
Storage Architecture:
graph LR
subgraph "Storage Engine"
T[Topic]
P1[Partition 0]
P2[Partition 1]
P3[Partition 2]
T --> P1
T --> P2
T --> P3
P1 --> Q1[Message Queue]
P2 --> Q2[Message Queue]
P3 --> Q3[Message Queue]
end
PublishRequest to BrokerPublishResponse with message ID and offsetConsumeRequest to BrokerRafka uses hash-based partitioning for efficient message distribution:
fn hash_key(&self, key: &str) -> u32 {
key.bytes().fold(0u32, |acc, b| acc.wrapping_add(b as u32))
}
fn owns_partition(&self, message_key: &str) -> bool {
let hash = self.hash_key(message_key);
hash % self.total_partitions == self.partition_id
}
Configurable message retention based on:
Built-in metrics for monitoring:
./scripts/helloworld.sh
Basic producer-consumer interaction demonstration.
./scripts/partitioned_demo.sh
Multi-broker setup with hash-based partitioning.
./scripts/retention_demo.sh
Demonstrates message retention policies.
./scripts/offset_tracking_demo.sh
Shows consumer offset management and recovery.
# Clone repository
git clone https://github.com/yourusername/rafka.git
cd rafka
# Build all crates
cargo build
# Run tests
cargo test
# Build release version
cargo build --release
# Run all tests
cargo test
# Run specific crate tests
cargo test -p rafka-storage
cargo test -p rafka-broker
The project follows Rust best practices with:
โ ๏ธ Early Development - Not Production Ready
Rafka is currently in active development. The current implementation provides:
โ Completed Features:
๐ In Progress:
๐ Planned Features:
We welcome contributions! Here are some areas where you can help:
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ in Rust