Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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)

NameDescription
jemallocjemalloc (not available on MSVC)
mimalloc-allocmimalloc (works everywhere including MSVC)

HTTP Middleware Layers

Tower-HTTP middleware for your service

NameDescription
http-catch-panicConvert panics to 500 responses
Crates: tower, tower-http
http-on-early-dropHandle early client disconnects
Crates: tower, tower-http
http-request-idX-Request-Id propagation
Crates: tower, tower-http
http-timeoutRequest timeout enforcement
Crates: tower, tower-http
http-traceRequest/response tracing spans
Crates: tower, tower-http

Dependencies

NameDescription
anyhowFlexible concrete Error type built on std::error::Error
axumHTTP routing and request handling library that focuses on ergonomics and modularity
clapA simple to use, efficient, and full-featured Command Line Argument Parser
criterion
dial9-tokio-telemetry
failsafe
httpA set of types for representing HTTP requests and responses.
metriqueLibrary for generating wide event metrics
metrique-utilAdditional utilities for metrique
moka
reqwesthigher level HTTP client library
serdeA generic serialization/deserialization framework
serde_jsonA JSON serialization file format
thiserrorderive(Error)
tokioAn event-driven, non-blocking I/O platform for writing asynchronous I/O backed applications.
tower_governor
tracingApplication-level tracing for Rust.
tracing-appenderProvides utilities for file appenders and making non-blocking writers.
tracing-subscriberUtilities for implementing and composing tracing subscribers.

Templates

NameDescription
serviceResilient request-response service (axum or hyper) with observability, graceful shutdown, and a Redis or HTTP downstream