backend-service-battery-pack
Opinionated, curated dependencies, templates, and skills for building simple but resilient async backend services in Rust.
Generate a service
cargo bp new backend-service --template service
Add to an existing project
Pull the curated dependencies into a project you already have:
cargo bp add backend-service
Inspect it first
cargo bp show backend-service # crates, features, and templates
cargo bp show backend-service -t service # preview the rendered template
See the backend service skills for guidance on the observability, resilience, and performance choices these templates make.
Battery pack contents
Global Allocator (pick at most one)
Pick a high-performance allocator (or use the system default)
| Name | Description |
|---|---|
jemalloc | jemalloc (not available on MSVC) |
mimalloc-alloc | mimalloc (works everywhere including MSVC) |
HTTP Middleware Layers
Tower-HTTP middleware for your service
| Name | Description |
|---|---|
http-catch-panic | Convert panics to 500 responses |
Crates: tower, tower-http | |
http-on-early-drop | Handle early client disconnects |
Crates: tower, tower-http | |
http-request-id | X-Request-Id propagation |
Crates: tower, tower-http | |
http-timeout | Request timeout enforcement |
Crates: tower, tower-http | |
http-trace | Request/response tracing spans |
Crates: tower, tower-http |
Dependencies
| Name | Description |
|---|---|
anyhow | Flexible concrete Error type built on std::error::Error |
axum | HTTP routing and request handling library that focuses on ergonomics and modularity |
clap | A simple to use, efficient, and full-featured Command Line Argument Parser |
criterion | |
dial9-tokio-telemetry | |
failsafe | |
http | A set of types for representing HTTP requests and responses. |
metrique | Library for generating wide event metrics |
metrique-util | Additional utilities for metrique |
moka | |
reqwest | higher level HTTP client library |
serde | A generic serialization/deserialization framework |
serde_json | A JSON serialization file format |
thiserror | derive(Error) |
tokio | An event-driven, non-blocking I/O platform for writing asynchronous I/O backed applications. |
tower_governor | |
tracing | Application-level tracing for Rust. |
tracing-appender | Provides utilities for file appenders and making non-blocking writers. |
tracing-subscriber | Utilities for implementing and composing tracing subscribers. |
Templates
| Name | Description |
|---|---|
service | Resilient request-response service (axum or hyper) with observability, graceful shutdown, and a Redis or HTTP downstream |