A modern template for building production-ready Rust microservices. Clone this project to kickstart services with:
- GraphQL over HTTP using
axum(web) - gRPC with Protobuf using
tonic(rpc) - Kafka consumer using
rdkafkaandsea-streamer(bus) - Kafka producer using
debeziumusing the Outbox Pattern - PostgreSQL with
sqlxandsea-query - Observability with
opentelemetryand Jaeger - Async runtime powered by
tokio
Ideal for software engineers looking to quickly scaffold scalable and testable microservices in Rust.
Install the following tools:
- asdf version manager
- Required
asdfplugins: - Docker for running dependencies (Postgres, Kafka, Jaeger, etc.)
Run the following:
docker-compose up -d # Start database, Kafka, Jaeger, etc.
asdf install # Install tool versions from .tool-versions
task install # Install dependencies and tooling
task migrate # Run database migrations
./register-debezium.sh # Register Debezium for CDC (optional)If you see an error about sqlx not found, run:
asdf reshimStart individual services using Cargo:
- Web Server:
cargo run -p web
- RPC Server:
cargo run -p rpc
- Bus Server:
cargo run -p bus
Send a mutation to the GraphQL endpoint:
curl -X POST http://localhost:4000/graph \
-H "Content-Type: application/json" \
-d '{
"query": "mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id firstName lastName createdAt } }",
"variables": {
"input": {
"firstName": "John",
"lastName": "Doe"
}
}
}'This will trigger both a database write and a message to Kafka (via the outbox table).
Call the gRPC GetUser method using grpcurl:
grpcurl -plaintext \
-import-path ./protos \
-proto protos/example/users/v1/rpc/users.proto \
-d '{ "id": "<YOUR USER ID>" }' \
0.0.0.0:50051 \
example.users.v1.rpc.Users/GetUserTo test the Kafka consumer flow:
- Run the Debezium registration script:
./register-debezium.sh
- Start the bus server:
cargo run -p bus
- Trigger a GraphQL mutation (as shown above under Web Server).
The Bus Server will consume the message published by Debezium and process it.
A basic GitHub Actions workflow is available in .github/workflows/ci.yml. It includes steps for:
- Formatting and linting
- Running tests
.
βββ workspace/
β βββ base/ # Business logic
β βββ web/ # GraphQL server
β βββ rpc/ # gRPC server
β βββ bus/ # Kafka consumer
β βββ meta/ # Test macros
βββ protos/ # Protobuf definitions
βββ migrations/ # Database migrations
βββ docs/ # Service documentation
βββ buf.yaml # Protobuf linter
βββ docker-compose.yaml # Docker containers
βββ register-debezium.sh # Debezium connector
βββ taskfile.yaml # Task runner commands
βββ .github # GitHub Actions
βββ .tool-versions # asdf tool versionsThis project is a template and not meant for external PRs. Feel free to fork it and make it your own!