π A minimal, Kafka-inspired clustered message streaming system in Go. Launch a broker cluster with any number of brokers, create topics with any number of partitions, and interactively produce and consume messagesβpartition ownership is distributed across brokers just like in real Kafka!
- Multi-Broker Clustering: Start N brokers at once, each automatically aware of peers.
- Any Partition Count: Create topics with any number of partitions, independently of broker count.
- Round-Robin Assignment: Partitions are spread evenly across brokers (round-robin).
- HTTP APIs: Create topics, list topics, produce to and consume from any partition over HTTP.
- CLI Producer & Consumer: Simple interactive clients for message publishing and consumption.
- Persistent Logs: Each partition's data is stored on disk and survives restarts.
- Go 1.19 or higher
git clone https://github.com/rohankumardubey/StreamNest.git
cd StreamNest
go mod tidy
go build -o stream-nest-cluster ./cmd/stream-nest-cluster
Run this in one terminal (spawns all brokers as subprocesses):
./stream-nest-cluster broker --count=3
Each will print:
Starting broker 1 on port 8080 with peers: localhost:8081,localhost:8082
Broker 1 running on :8080
Starting broker 2 on port 8081 with peers: localhost:8080,localhost:8082
Broker 2 running on :8081
Starting broker 3 on port 8082 with peers: localhost:8080,localhost:8081
Broker 3 running on :8082
In a second terminal, run:
curl -X POST -H "Content-Type: application/json" \
-d '{"topic":"demo","partitions":7}' \
http://localhost:8080/create-topic
Response:
{"status":"created"}
curl http://localhost:8080/list-topics
Response:
{"topics":["test"]}
curl http://localhost:8080/metadata
Response Example:
{
"topic_partitions": {
"demo": {
"partitions": [
{"partition":0,"broker":"localhost:8080"},
{"partition":1,"broker":"localhost:8081"},
{"partition":2,"broker":"localhost:8082"},
{"partition":3,"broker":"localhost:8080"},
{"partition":4,"broker":"localhost:8081"},
{"partition":5,"broker":"localhost:8082"},
{"partition":6,"broker":"localhost:8080"}
]
}
}
}
Register a schema for a topic:
curl -X POST -H "Content-Type: application/json" \
-d '{
"topic":"demo",
"schema":{
"type":"object",
"properties":{
"name":{"type":"string"},
"age":{"type":"number"}
},
"required":["name","age"]
}
}' \
http://localhost:8080/register-schema
Note: If you are registering a schema in Schema Registry, you must send the messages in the schema defined in schema registry format; otherwise the messages will be ignored by the consumer due to strict Schema Registry validations.If you are unaware of the schema just ignore this step so no validations happen and broker & consumer accepts all messages.
Producing a valid message with the schema from /produce endpoint
(if you plan to specify the partition value manually without key then it will send the message to specified partition)
curl -X POST -H "Content-Type: application/json" \
-d '{
"topic":"demo",
"partition":0,
"message":"{\"name\":\"Alice\",\"age\":30}"
}' \
http://localhost:8080/produce
(if no partition value is specified and key is given then it will calculate partition based on hash function)
curl -X POST -H "Content-Type: application/json" \
-d '{
"topic":"demo",
"key": "id1",
"message":"{\"name\":\"Alice\",\"age\":30}"
}' \
http://localhost:8080/produce
(if no partition value and no key is given then it will follow the round robin strategy)
curl -X POST -H "Content-Type: application/json" \
-d '{
"topic":"demo",
"message":"{\"name\":\"Alice\",\"age\":30}"
}' \
http://localhost:8080/produce
Producing a valid message without schema from CLI
./stream-nest-cluster producer --meta=localhost:8080
Response
Enter topic: demo
Partitions:
0 on localhost:8080
1 on localhost:8081
2 on localhost:8082
3 on localhost:8080
4 on localhost:8081
5 on localhost:8082
6 on localhost:8080
Partition?> 4
Type messages (or 'exit'):
> Hello
offset: 0
> Another message
offset: 1
> exit
./stream-nest-cluster consumer --meta=localhost:8080
Response
Enter topic: demo
Partitions:
0 on localhost:8080
1 on localhost:8081
2 on localhost:8082
3 on localhost:8080
4 on localhost:8081
5 on localhost:8082
6 on localhost:8080
Partition?> 4
[Offset 0] Hello
[Offset 1] Another message
Each broker exposes Prometheus metrics on /metrics
. Metrics are registered automatically when a broker starts.
Query a broker's metrics with curl:
curl http://localhost:8080/metrics
You should see counters such as streamnest_messages_produced_total
and streamnest_messages_consumed_total
that increment as you produce and consume messages.
StreamNest/
βββ cmd/
β βββ stream-nest-cluster/
β βββ main.go
βββ internal/
β βββ broker/
β β βββ types.go
β β βββ storage.go
β β βββ broker.go
β βββ client/
β βββ client.go
βββ data/ # runtime logs: <topic>_<partition>.log
βββ go.mod
βββ README.md
- Replication & Failover β mirror partitions across brokers
- Consumer Groups β manage offsets per group
- Docker Compose β launch cluster with a single command
- Metrics & Monitoring β Prometheus endpoints
- Fork the repo
- Create a branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add cool feature'
- Push to your branch:
git push origin my-feature
- Open a Pull Request
This project is licensed under the MIT License. See LICENSE for details.