Skip to content
Public template

About

πŸ¦€ A modern Rust microservice template with GraphQL, gRPC, Kafka, PostgreSQL, and full observability out of the box.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

πŸ¦€ Rust Service Template

Introduction

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 rdkafka and sea-streamer (bus)
  • Kafka producer using debezium using the Outbox Pattern
  • PostgreSQL with sqlx and sea-query
  • Observability with opentelemetry and Jaeger
  • Async runtime powered by tokio

Ideal for software engineers looking to quickly scaffold scalable and testable microservices in Rust.

πŸš€ Getting Started

Pre-requisites:

Install the following tools:

  1. asdf version manager
  2. Required asdf plugins:
  3. Docker for running dependencies (Postgres, Kafka, Jaeger, etc.)

Setup

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 reshim

πŸ§ͺ Running Services

Start individual services using Cargo:

  • Web Server:
    cargo run -p web
  • RPC Server:
    cargo run -p rpc
  • Bus Server:
    cargo run -p bus

πŸ” Manual Testing

Web Server (GraphQL)

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).

RPC Server (gRPC)

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/GetUser

Bus Server (Kafka Consumer)

To test the Kafka consumer flow:

  1. Run the Debezium registration script:
    ./register-debezium.sh
  2. Start the bus server:
    cargo run -p bus
  3. Trigger a GraphQL mutation (as shown above under Web Server).

The Bus Server will consume the message published by Debezium and process it.

βš™οΈ Continuous Integration

A basic GitHub Actions workflow is available in .github/workflows/ci.yml. It includes steps for:

  • Formatting and linting
  • Running tests

🧱 Project Structure

.
β”œβ”€β”€ 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 versions

🀝 Contributing

This project is a template and not meant for external PRs. Feel free to fork it and make it your own!

About

πŸ¦€ A modern Rust microservice template with GraphQL, gRPC, Kafka, PostgreSQL, and full observability out of the box.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages