Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Latest commit

History

547 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

hyperi-rustlib

Build StatusCrates.iodocs.rsLicense

There's plenty of sage advice out there about how to run Rust services in production at scale — config cascades, structured logging, masking secrets, multi-backend secrets management, Prometheus, OpenTelemetry, Kafka transports, tiered disk-spillover sinks, adaptive worker pools, graceful shutdown — but almost none of it as code you can just install and use.

This is that code.

Opinionated, drop-in, working out of the box. The patterns from blog posts, watercooler chats and beers with your Google mates as actual library — not a framework you assemble from twenty crates and 8 weeks of munging.

Built as the foundation for HyperI's PB/hr data services. Generic enough that you don't need to be at HyperI to use it.

This module exists because of this — https://www.youtube.com/watch?v=xE9W9Ghe4Jk — but for the backend. And of course, no microservices.

Quick Start

[dependencies]
hyperi-rustlib = "2"

Default features: config, logger. Add the others you want explicitly.

use hyperi_rustlib::{config, logger, env};fnmain() -> anyhow::Result<()>{let environment = env::Environment::detect();
logger::setup_default()?;
config::setup(config::ConfigOptions{env_prefix:"MYAPP".into(),
..Default::default()})?;
tracing::info!("Running in {environment:?}");Ok(())}

Features

Pick the slice you need; pay only for what you use.

FeatureDescription
envEnvironment detection (K8s, Docker, Container, BareMetal)
runtimeRuntime path resolution (XDG/container-aware)
config8-layer config cascade (figment-based)
config-reloadSharedConfig<T> + ConfigReloader hot-reload
config-postgresPostgreSQL config source
loggerStructured logging, JSON/text auto-detect, sensitive-field masking
metricsPrometheus metrics + process/container metrics
otel-metricsOpenTelemetry metrics export (OTLP)
otel-tracingOpenTelemetry distributed tracing
httpHTTP client with retry middleware (reqwest)
http-serverAxum HTTP server with health probe trinity (/healthz/{startup,live,ready})
transport-kafkaKafka transport (rdkafka, dynamic-linking)
transport-grpcgRPC transport (tonic/prost)
transport-memoryIn-memory transport (testing/dev)
transport-grpc-vector-compatVector wire-protocol compatibility
spoolDisk-backed async FIFO queue (yaque + zstd)
tiered-sinkResilient delivery: hot buffer + circuit breaker + disk spillover
secretsSecrets management core (file backend)
secrets-vaultOpenBao / HashiCorp Vault provider
secrets-awsAWS Secrets Manager provider
directory-configYAML directory-backed config store
directory-config-gitGit integration for directory-config (git2)
scalingBack-pressure / scaling-pressure primitives
cliStandard CLI framework (clap)
topTUI metrics dashboard (ratatui)
ioFile rotation, NDJSON writer
dlqDead-letter queue (file backend)
dlq-kafkaDLQ Kafka backend
output-fileFile output sink
expressionCEL expression evaluation
deploymentDeployment-contract validation
version-checkOptional startup version check
resilienceCircuit breaker, retry, bulkhead (tower-resilience)
fullEverything

Native System Dependencies

This crate dynamically links against system C libraries for several features. Both build hosts and deployment targets need the appropriate packages.

Build Host (CI / Development)

FeatureCrateBuild PackageNotes
transport-kafkardkafka-syslibrdkafka-dev (>= 2.12.1)Requires Confluent APT repo — Ubuntu's default is too old
directory-config-gitlibgit2-syslibgit2-dev, libssh2-1-devSystem lib avoids vendored C build
spool, tiered-sinkzstd-syslibzstd-devSystem lib avoids vendored C build
(transitive)libz-syszlib1g-devUsed by multiple deps
(transitive)openssl-syslibssl-devDynamic linking via pkg-config
secrets-awsaws-lc-sysC/C++ compiled from source (no system lib available); ~20–30s first build, cached by sccache

For librdkafka-dev >= 2.12.1, add the Confluent APT repo:

curl -fsSL https://packages.confluent.io/clients/deb/archive.key \
| sudo gpg --dearmor -o /usr/share/keyrings/confluent-clients.gpg
echo"deb [signed-by=/usr/share/keyrings/confluent-clients.gpg] \ https://packages.confluent.io/clients/deb noble main" \
| sudo tee /etc/apt/sources.list.d/confluent-clients.list
sudo apt-get update
sudo apt-get install -y librdkafka-dev libssl-dev libsasl2-dev pkg-config

Deployment Host (Runtime)

The compiled binary links against .so files at runtime. Install the runtime packages (not -dev) on deployment hosts or in Docker images.

FeatureRuntime PackageShared Object
transport-kafkalibrdkafka1 (from Confluent repo)librdkafka.so.1
directory-config-gitlibgit2-1.7 (or matching version)libgit2.so
spool, tiered-sinklibzstd1libzstd.so.1
(transitive)zlib1glibz.so.1
(transitive)libssl3libssl.so.3

Only install what you use. Check the features your binary enables to determine which runtime packages are needed.

Docker Example

# Build stageFROM rust:1 AS builder
RUN apt-get update && apt-get install -y \
pkg-config libssl-dev librdkafka-dev libgit2-dev libzstd-dev
COPY . .
RUN cargo build --release
# Runtime stageFROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
librdkafka1 libssl3 libgit2-1.7 libzstd1 ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/myapp /usr/local/bin/

For librdkafka1, add the Confluent APT repo to both build and runtime stages.

Health Check Endpoints — The Probe Trinity

For services deployed to Kubernetes, the http-server feature provides the three K8s probe types:

ProbePathChecksOn failure
Startup/healthz/startupInit completeK8s waits, then restarts
Liveness/healthz/liveProcess not deadlockedRestart pod
Readiness/healthz/readyDeps healthy + ready flag setStop routing traffic

Liveness MUST NEVER check downstream dependencies (a DB outage shouldn't restart your replicas). Readiness checks dependencies AND requires an explicit set_ready() call — cleared during graceful shutdown.

Self-regulation (default vertical scaling)

A rustlib data-plane app regulates its own intake. Sized for steady state, a pod slows down or speeds up WITHIN itself first -- the default, fast, local response to a burst, a stalled upstream, or a transform that balloons memory. Only when that vertical headroom is exhausted does it escalate to horizontal scale (KEDA adding pods), driven by the same pressure signal. Memory is the hard, never-OOM authority; CPU is left to the kernel scheduler (CFS), which the byte-budget loop reads through longer process times. It is ON by default and opt-out via self_regulation.enabled = false. See docs/SELF-REGULATION.md.

Architecture

See docs/ for the full documentation index — docs/ARCHITECTURE.md for the module map and layering, and docs/core-pillars/CONFIG.md for the 8-layer config cascade reference.

License

BUSL-1.1 — Business Source License 1.1, transitions to Apache 2.0 after 3 years.

Related

  • hyperi-pylib — sister library for Python services. Same opinions, same patterns, expressive Python ergonomics for control planes, APIs, and integration layers.

About

Opinionated, drop-in Rust toolkit for production services at scale. The patterns from blog posts as actual code: 8-layer config cascade, structured logging with PII masking, Prometheus + OpenTelemetry, tiered disk-spillover sinks, Kafka/gRPC transports, adaptive worker pools, graceful shutdown.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages