bb8

A full-featured async connection pool for Rust, built on Tokio.

Library
Cargo
v0.9.1
950stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity72
Maintenance48
Community68
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality85
Innovation72
Learning Curve72

bb8 is a generic, asynchronous connection pool for Rust, designed for Tokio-based applications and modeled after the synchronous r2d2 pool. Instead of opening a fresh database connection for every request — which is both slow and prone to resource exhaustion under load — bb8 maintains a managed set of live connections and hands them out for reuse, returning them to the pool when dropped.

bb8 is agnostic to the connection type it manages: backends implement the ManageConnection trait to supply the logic for creating and health-checking connections. Adapter crates such as bb8-postgres and bb8-redis provide ready-made integrations, and the pool handles sizing, idle timeouts, connection lifetimes, and health validation so applications get reliable, efficient access to their backends.

What You Get

  • An async, Tokio-based connection pool with configurable sizing and lifetimes
  • A generic ManageConnection trait so any connection type can be pooled
  • Automatic health checking and recycling of broken or expired connections
  • Ready-made backend adapters (bb8-postgres, bb8-redis) in the same workspace
  • RAII-style checkout where connections return to the pool on drop

Common Use Cases

  • Pooling async PostgreSQL connections in a high-traffic Tokio web service
  • Reusing Redis connections across many concurrent async tasks
  • Building a custom pool for any backend by implementing ManageConnection
  • Bounding concurrent database connections to avoid resource exhaustion

Under The Hood

Architecture - The core bb8 crate is small and layered: lib.rs re-exports the public surface, api.rs defines the Pool, PooledConnection, Builder, and the ManageConnection trait, while inner.rs and internals.rs hold the shared pool state — a set of idle connections behind synchronization, plus reaper logic for idle-timeout and max-lifetime enforcement. Checkout awaits an available connection (or creation of a new one up to the max), optionally validates it via the manager, and a PooledConnection guard returns it on drop. The workspace also contains postgres/ (bb8-postgres) and redis/ (bb8-redis) adapters implementing ManageConnection.

Tech Stack - Pure Rust built on the Tokio async runtime, using async/await and futures. It is a Cargo workspace with resolver 2, includes deny.toml for supply-chain/license auditing via cargo-deny, and runs CI with codecov coverage.

Code Quality - Mature and well-tested with CI, code coverage, and a clear separation between the public API and internal pool mechanics. As a long-lived crate originally derived from r2d2, its concurrency-sensitive internals are carefully scoped, and the small surface area keeps the implementation auditable.

API Design - Ergonomic and idiomatic: build a pool with Pool::builder().max_size(n).build(manager).await, then pool.get().await? yields a guard that derefs to the underlying connection. Modeling on r2d2 makes it instantly familiar to Rust developers, and the ManageConnection trait cleanly separates pool mechanics from backend specifics, so writing a new adapter is minimal boilerplate.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search