Skip to content
CAI
Software that uses CAICheck a score

tower-rs/tower

65.1

Adequate · 30 September 2026

12.3k

lines of production code

Rust

primary language

2

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

Tower is a Rust library that provides a protocol-agnostic abstraction for asynchronous request and response handling, enabling the construction of modular network clients and servers. It offers a comprehensive middleware system where services can be decorated with layers for concerns such as load balancing, retrying, rate limiting, and timeouts. The system supports dynamic service discovery and routing, allowing developers to compose complex, resilient service stacks declaratively.

How it got here

2016–2019 — Tower workspace restructuring and core abstractions

12 changes.

The project was restructured into a Cargo workspace, establishing the foundational tower-service and tower-layer crates with no\_std support. This period focused on defining the core Service trait and Layer composition utilities, alongside introducing the ServiceBuilder for declarative middleware stacking. Comprehensive testing infrastructure was also added via the tower-test crate to validate layer composition and service behavior.

2020–2022 — comprehensive middleware expansion

31 changes.

This period focused on significantly expanding the Tower middleware ecosystem by introducing new modules for load balancing, service discovery, and request routing. It also involved substantial refactoring of existing components like Buffer and Filter to improve performance and flexibility, alongside the addition of advanced features such as retry budgets and connection recovery.

Features

Add Shared MakeService for cloning buffered services

A new \Shared\ type has been added to the \tower::make\ module, allowing a service to be wrapped so that it can be cloned for each new connection. This is particularly useful when combined with \tower::buffer::Buffer\, enabling a single buffered service instance to be shared across multiple connections by cloning the buffer handle. The implementation includes tests verifying its behavior as both a \MakeService\ and a standard \Service\.

_tower/src/make/make\service · high confidence

Add rate limiting layer for Tower services

Introduces a new \RateLimitLayer\ and associated \RateLimit\ service in \tower/src/limit/rate\ that enforces a maximum number of requests over a specified time period. The implementation uses Tokio's time utilities to track remaining requests and sleep when the limit is reached, resetting the counter once the period elapses. This allows users to wrap existing Tower services to prevent them from being overwhelmed by excessive traffic.

tower/src/limit/rate · high confidence

Add retry budget mechanism to prevent retry storms

Introduces a new \Budget\ trait and \TpsBudget\ implementation in the retry module, allowing users to limit retries based on a time-windowed token bucket rather than a fixed maximum attempt count. This helps prevent retry storms by dynamically adjusting the allowed retry rate based on recent failure rates, with \TpsBudget\ providing a transactions-per-minute based approach to manage retry tokens.

tower/src/retry/budget · high confidence

Add timeout middleware to tower

Introduces a new \Timeout\ service layer that aborts requests if they do not complete within a specified duration. Users can now wrap existing services with \TimeoutLayer\ to enforce time limits, receiving an \Elapsed\ error when the timeout is exceeded.

tower/src/timeout · high confidence

Add tower-test mock service for testing Tower layers

The tower-test crate now includes a mock service implementation (tower-test/src/mock) that allows developers to test Tower layers and services in isolation. This new module provides a Mock service and Handle pair for capturing requests and sending responses, along with a Spawn wrapper that integrates with tokio\_test's task simulation to check waker behavior. The mock supports configurable request limits, error injection, and cloning, enabling comprehensive unit testing of service stacks without requiring real network connections or external dependencies.

tower-test/src/mock · high confidence

Introduce LoadShed middleware to shed requests when services are not ready

Adds a new \LoadShed\ service and \LoadShedLayer\ to the Tower middleware collection. This middleware allows applications to immediately reject requests with an \Overloaded\ error when the underlying inner service is not ready, rather than waiting for it to become ready. This behavior is useful for shedding load during traffic spikes to prevent backpressure from propagating upstream. The implementation includes a public \Overloaded\ error type for handling these rejections.

_tower/src/load\shed · high confidence

Introduce Optional service utility for conditional request forwarding

Added a new \Optional\ service wrapper in \tower/src/util/optional\ that conditionally forwards requests to an inner service. If the inner service is \None\, the wrapper returns a specific \None\ error instead of attempting to call a service. This change introduces dedicated modules for error handling (\error.rs\) and response futures (\future.rs\) to manage the optional state, ensuring that \None\ services are always considered ready and return a standardized error when called.

tower/src/util/optional · high confidence

Introduce P2C load balancing middleware

Adds a new \tower::balance\ module implementing the Power of Two Random Choices (P2C) algorithm to distribute requests across multiple services. This includes the \Balance\ service, \MakeBalance\ factory, and \MakeBalanceLayer\ for integrating with the tower layer system. The implementation relies on the \Discover\ trait for dynamic service discovery and uses a \ReadyCache\ to manage endpoint states. A key behavioral detail is that the cached P2C ready index is cleared upon service discovery removal to prevent dispatching to incorrectly swapped-in endpoints.

tower/src/balance · high confidence

Introduce ReadyCache for managing service readiness

Added a new \ReadyCache\ component in \tower/src/ready\_cache\ that maintains a set of pending and ready services, allowing users to drive readiness via polling and dispatch requests only to services confirmed as ready. The implementation includes a dedicated error type (\Failed\) that exposes the underlying error source, and uses \indexmap\ for ordered storage of services.

_tower/src/ready\cache · high confidence

Introduce ServiceBuilder for declarative layer composition

A new \ServiceBuilder\ type is added to \tower/src/builder\, providing a builder-style API for composing middleware layers around a \Service\. This allows users to declaratively chain layers (such as buffering, concurrency limiting, and timeouts) in a specific order, where the order of addition determines the request handling pipeline. The builder supports adding custom layers via \layer\, function-based layers via \layer\_fn\, and optional layers via \option\_layer\, simplifying the construction of complex service stacks.

tower/src/builder · high confidence

Introduce SpawnReady to drive services to readiness on a background task

Adds the \SpawnReady\ service and \SpawnReadyLayer\ to the Tower library. This new component allows users to wrap an existing service so that its readiness is driven asynchronously on a background Tokio task. When the inner service is not yet ready, \SpawnReady\ spawns a task to wait for readiness, allowing the main service loop to remain responsive. The implementation ensures that if the \SpawnReady\ wrapper is dropped while a background task is still running, that task is aborted to prevent resource leaks.

_tower/src/spawn\ready · high confidence

Introduce generic retry layer with configurable backoff and policy traits

The retry middleware has been restructured to support flexible, composable retry strategies. Users can now define custom retry behaviors by implementing the new \Policy\ trait, which allows mutating requests and results during retry attempts. The module includes a generic \Backoff\ trait and a built-in \ExponentialBackoff\ implementation with configurable jitter, minimum/maximum delays, and random number generator support. The \RetryLayer\ and \Retry\ service types have been updated to work with these new abstractions, requiring the inner service and policy to implement \Clone\ to support request cloning across retry sessions.

tower/src/retry · high confidence

Introduce service discovery module with static list support

Adds a new \tower::discover\ module that provides a \Discover\ trait for handling dynamic sets of services via \Change\ events (insertions and removals). This release includes a \ServiceList\ implementation for static service discovery based on a predetermined list, which yields its contents once and then completes. The \Change\ enum is now \Clone\, and the \Discover\ trait is sealed to prevent external implementations.

tower/src/discover · high confidence

Introduce service load measurement and completion tracking

This change adds a new \tower::load\ module that provides a \Load\ trait and several implementations for measuring service load, including \Constant\ (for testing), \PendingRequests\ (counting in-flight requests), and \PeakEwma\ (using an exponentially-weighted moving average of peak latency). It also introduces a \TrackCompletion\ trait and \CompleteOnResponse\ default, allowing load metrics to accurately track request lifecycles beyond the initial response future, which is essential for balancing services that handle long-running streams.

tower/src/load · high confidence

Introduce the \`tower-hedge\` middleware for pre-emptive request retrying

Adds a new \tower-hedge\ module that implements a middleware to pre-emptively retry requests that have been outstanding longer than a specified latency percentile. The implementation includes a \Hedge\ service that clones requests based on a configurable policy, sends the original request to one service instance and a delayed clone to another, and returns the result of whichever completes first. The module also introduces supporting components: a \Delay\ middleware to postpone the retry request, a \Latency\ middleware to record request durations into a rotating histogram, and a \Select\ middleware to race the two futures. This allows users to improve perceived latency for slow or stalled requests by automatically hedging them against a second backend instance.

tower/src/hedge · high confidence

Introduce tower-layer crate with Layer trait and composition utilities

The \tower-layer\ crate is introduced, providing the foundational \Layer\ trait for decorating services with middleware. This release adds key composition tools including \Identity\ (a no-op layer), \Stack\ (for chaining two layers), and \layer\_fn\ (for creating layers from closures). It also enables composing up to 16 layers using tuple syntax and implements \Layer\ for references to layers, allowing flexible service decoration without requiring new struct definitions for simple transformations.

tower-layer/src · high confidence

Introduce tower-test crate with mock Service and assertion macros

A new \tower-test\ crate has been added to provide testing utilities for Tower services. It includes a \mock\ module containing a mock \Service\ implementation and a \SendResponse\ handle for simulating service behavior in tests. Additionally, the \assert\_request\_eq!\ macro is provided to simplify assertions that a mock handle receives a specific request, allowing tests to verify request flow and send responses easily.

tower-test/src · high confidence

Introduction of the core \`Service\` trait with \`no\_std\` support

The \tower-service\ crate now defines the foundational \Service\ trait, providing a protocol-agnostic abstraction for asynchronous request/response handling that works in both \std\ and \no\_std\ environments. This change establishes the core interface for Tower, allowing developers to write modular network clients and servers by implementing the \Service\ trait, which decouples application logic from underlying protocols like HTTP or Redis.

tower-service/src · high confidence

New Reconnect service for automatic connection recovery

Tower introduces a new \Reconnect\ service combinator that wraps an existing service to automatically handle connection failures. When the underlying service fails to connect or becomes unavailable, \Reconnect\ transparently attempts to re-establish the connection on subsequent requests, allowing users to continue sending requests without manual intervention. The implementation includes a dedicated \ResponseFuture\ to manage the asynchronous connection state and error handling, ensuring that connection errors are surfaced appropriately while maintaining the service's readiness state.

tower/src/reconnect · high confidence

New \`make\` module with \`MakeService\` and \`MakeConnection\` traits

A new \tower::make\ module has been introduced to provide trait aliases for services that produce specific types of responses. This module exposes the \MakeService\ trait, which acts as a factory for creating new \Service\ values (useful for scenarios like TCP server listeners), and the \MakeConnection\ trait, used for creating \AsyncRead + AsyncWrite\ transports. The \MakeService\ trait includes helper methods \into\_service\ and \as\_service\ to convert the factory into a standard \Service\. Additionally, a \Shared\ wrapper and \SharedFuture\ type are included to support shared state across service instances.

tower/src/make · high confidence

New boxed layer helpers for dynamic service construction

Tower now provides \BoxLayer\, \BoxCloneServiceLayer\, and \BoxCloneSyncServiceLayer\ in the \tower::util::boxed\ module, allowing users to create layers dynamically that erase the underlying service type while maintaining consistent return types. This enables conditional layer composition (e.g., adding a timeout only if an environment variable is set) without requiring all branches to share the same concrete layer type. These new helpers complement the existing \BoxService\ and \BoxCloneService\ types, extending dynamic dispatch capabilities to the layering middleware system.

tower/src/util/boxed · high confidence

New load balancer exercise example

Added tower/examples/tower-balance.rs, an example that exercises load balancers with mocked services to demonstrate P2C+PeakEWMA and P2C+LeastLoaded strategies.

tower/examples · high confidence

New tower-steer module for request routing between services

A new \tower-steer\ module has been added to \tower/src/steer\, introducing the \Steer\ service and \Picker\ trait. This allows users to route incoming requests to one of several underlying services based on custom logic (e.g., creating a router similar to web frameworks). The \Steer\ service waits for all underlying services to be ready before dispatching a request, which may cause head-of-line blocking unless paired with buffering services. The module also implements \Clone\ and \Debug\ for \Steer\ when the underlying services and router support it.

tower/src/steer · high confidence

New utility types and service combinators in tower::util

The \tower/src/util\ module has been expanded with several new service combinators and utility types. Users can now chain post-processing logic on responses using \and\_then\ and \then\, or transform requests, responses, errors, and futures via \map\_request\, \map\_response\, \map\_err\, and \map\_future\. Conditional branching between two service implementations is supported by the new \Either\ combinator. For dynamic dispatch, \BoxCloneService\ and \BoxCloneSyncService\ allow cloning and sharing boxed services, while \FutureService\ enables treating a future that resolves to a service as a service itself. Additionally, lightweight random number generation utilities (\rng\) are now available for internal middleware use.

tower/src/util · high confidence

Project initialization and repository restructuring

This change establishes the initial state of the Tower project repository. It introduces the primary README.md with project overview, supported Rust versions (MSRV 1.64.0), and no\_std compatibility notes. It adds a new netlify.toml for documentation deployment and a deny.toml for dependency license and advisory checks. The change also removes legacy CI configurations (.travis.yml, appveyor.yml) and consolidates licensing by renaming LICENSE-MIT to LICENSE and deleting LICENSE-APACHE, updating the copyright holder to Tower Contributors.

(repo-wide) · high confidence

Removals

Removal of legacy tokio-service crate

The \src/lib.rs\ file containing the core \Service\ trait, \SimpleService\ implementation, and associated documentation has been deleted. This change removes the original tokio-service crate, which provided the foundational asynchronous service abstraction for network applications, indicating a shift away from this specific API surface.

src · high confidence

Behavioural changes

Concurrency limit now supports shared semaphores via GlobalConcurrencyLimitLayer

The concurrency limiting middleware has been refactored to use Tokio's \Semaphore\ and \PollSemaphore\ for managing concurrent request limits. A key behavioral change is the introduction of \GlobalConcurrencyLimitLayer\, which allows multiple services to share a single \Arc\<Semaphore\>\, enabling coordinated concurrency limits across different parts of an application. The core \ConcurrencyLimit\ service and its layer now wrap inner services using this semaphore-based permit system, ensuring that the number of in-flight requests never exceeds the configured maximum.

tower/src/limit/concurrency · high confidence

Refactored CallAll to use a shared core implementation with distinct ordered/unordered variants

The \call\_all\ utility has been restructured to share a common internal \CallAll\ struct (in \common.rs\) that handles the core polling logic, while exposing two public types: \CallAll\ (ordered responses via \FuturesOrdered\) and \CallAllUnordered\ (responses as they complete via \FuturesUnordered\). This change consolidates the stream-processing logic, ensuring consistent behavior for both ordering modes and simplifying the maintenance of the \Service\ interaction and error handling paths.

_tower/src/util/call\all · medium confidence

Rewrite of the Buffer middleware to use bounded MPSC channels

The \tower::buffer\ module has been rewritten to use Tokio's bounded multi-producer, single-consumer (MPSC) channel instead of the previous implementation. This change introduces new error types (\ServiceError\ and \Closed\) to distinguish between service failures and unexpected worker termination, and modifies the \Buffer\ service to be generic over the inner service's \Future\ type. Users will now see specific error handling for closed workers and backpressure is managed via the bounded channel capacity, with the \BufferLayer\ remaining the primary entry point for adding this buffering capability.

tower/src/buffer · high confidence

Rewrite of the tower filter module with new layer and future types

The \tower::filter\ module has been rewritten to introduce dedicated \FilterLayer\ and \AsyncFilterLayer\ types for constructing filter services, alongside new opaque future types (\ResponseFuture\ and \AsyncResponseFuture\) that manage the state machine for predicate checks and service calls. The \Filter\ and \AsyncFilter\ services now expose \check\, \get\_ref\, \get\_mut\, and \into\_inner\ methods, allowing users to inspect inner services and manually evaluate predicates, while the underlying implementation migrates to \pin\_project\_lite\ for more efficient pinning of the asynchronous state.

tower/src/filter · high confidence

Tower crate reorganization and layer module introduction

The tower crate has been reorganized to serve as a facade for the Tower ecosystem, re-exporting core traits from \tower-service\ and \tower-layer\ while introducing a new \layer\ module. This module exposes \Layer\, \LayerFn\, and \layer\_fn\ from \tower-layer\, along with utility types \Identity\ and \Stack\ (renamed from \Chain\) for combining layers. The crate now explicitly lists its sub-crates (\tower-service\, \tower-layer\, \tower-test\) and provides a \ServiceBuilder\ for composing middleware. Internal macros have been updated to use \pin\_project\_lite\ for opaque futures, and the crate enforces no unsafe code. The minimum supported Rust version (MSRV) is set to 1.64.0.

tower/src · medium confidence

Test coverage

Added integration tests for balance and load-shedding layers; Added test coverage for concurrency and rate limiting layers; Added test coverage for tower utility services and hedge layer; Added tests for AsyncFilter service behavior; Added tests for ReadyCache behavior; Added tests for ServiceBuilder and tracing span propagation; Added tests for SpawnReady service behavior; Added tests for retry policy behaviors; Added tests for the Buffer service; Added tests for the Steer service combinator; Added tests for tower-test mock service behavior.

Dependencies

Tower 0.5.3 release with workspace dependency management

This update releases Tower v0.5.3 and its sub-crates (tower-layer 0.3.3, tower-service 0.3.3, tower-test 0.4.1), restructuring the project into a Cargo workspace. The main crate now targets Rust 1.64.0 and relies on centralized workspace dependencies, including an upgrade to indexmap v2, http v1, and tokio v1.6.2. The examples directory has been added to demonstrate usage with the 'full' feature set.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 66 → 65 (-1.2)
  • Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.

Lenses

  • Code Health 99 → 99 (+0.0)
  • Architecture 100 → 94 (-5.8)
  • Maturity 57 → 57 (+0.0)
  • Readiness 64 → 61 (-3.1)
  • Security 67 → 67 (+0.0)
  • Performance 100 (new)

Resolved (5)

  • Concentrated knowledge decay
  • Documentation: no contributor guidance (README.md)
  • Documentation: no installation or build instructions (README.md)
  • Documentation: no usage examples (README.md)
  • Off-boarding risk: anonymized user #1

New (8)

  • Dormant codebase
  • Inverted test pyramid
  • Naming inconsistency between local and global concurrency limiters. ConcurrencyLimit is the service, ConcurrencyLimitLayer is the layer. GlobalConcurrencyLimitLayer is the layer for the global variant. The service for the global variant is not explicitly named in the snippet (likely ConcurrencyLimit is reused or missing a distinct name), but the layer naming GlobalConcurrencyLimitLayer vs ConcurrencyLimitLayer suggests a split. If the service is the same, the layer naming is inconsistent with the service naming convention.
  • Off the main sequence: tower-layer
  • Off-boarding risk: anonymized user #1
  • Potential overlap in mapping strategies. MapResult likely maps Result<Response, Error>. MapResponse maps Response. MapErr maps Error. While distinct, ServiceExt exposes map_result, map_response, and map_err. If MapResult is just a convenience for map_response + map_err composition, it's fine. However, if MapResult is intended to replace the combination of the other two, the API surface is fragmented. More critically, tower.util.and_then.AndThen and tower.util.then.Then (see above) often overlap with map_response in intent depending on closure signature.
  • Semantic ambiguity between 'and_then' and 'then'. In Rust async ecosystems (like futures), 'and_then' typically chains on the success value, while 'then' (or 'then') often handles both success and error (like map on Result/Future). However, looking at the signatures, both take a closure f: F and wrap an inner service. Without seeing the closure signature, it is highly likely these are duplicates or confusingly named variants of the same combinator (mapping the response). If AndThen maps Response -> Response and Then maps Response -> Response, they are redundant. If one handles errors, the naming is non-standard for the tower context where map_err exists separately.
  • Split tower

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

tower-rs/tower was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 30 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit df06d70dbea345facbffb5881fe8647f53bf424d — the exact code this score is about.
  • Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-cb25ca4feafa.