<!--
SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->
# Velo
Velo is a distributed messaging library for Rust. It gives active messages, typed streams, distributed events, large-payload transfer (with RDMA over UCX), and work queues over pluggable transports. It has peer discovery and Prometheus metrics built in.
NOTE: Velo is experimental. Its design, development, and tests are still in progress, and the APIs are not stable. Do not use Velo in production.
**Documentation: [the Velo book](https://ai-dynamo.github.io/velo/)**. The source is in [`docs/src/`](docs/src/SUMMARY.md).
Typed streams support graceful stop, cancellation, and ordered finalization, including prebound tickets. See [Stream lifecycle](docs/src/concepts/streaming.md).
A producer can wait until velo has handed a stream's output on: `StreamSender::retired()` resolves to `Sent` or `Discarded`. TCP and UDS write the frames that they admitted before they close at graceful shutdown. See [Know when the output has left](docs/src/concepts/streaming.md#know-when-the-output-has-left), and [Known limitations](docs/src/appendix/limitations.md) for what `Sent` does not cover yet.
Streams of bytes that the application already serialized can skip msgpack on both ends. `StreamSender<Bytes>::send_bytes` and `StreamAnchor<Bytes>::next_bytes` use the same frames as `send` and `next`, and the consumer gets each item as a slice of the received buffer, not a copy. See [Byte items](docs/src/concepts/streaming.md#byte-items).
Velo 0.19 gives Velo and Messenger explicit drop lifetimes, removes value-level Messenger cloning, and removes duplicate dispatch and cancellation APIs. See [Migrate ownership, dispatch, and cancellation](docs/src/guides/migrate-dispatch-and-cancellation.md).
Velo 0.21 makes `Velo` a handle. `VeloBuilder::build()` returns `Velo`, not `Arc<Velo>`. To share it, clone it. See [Migrate to the Velo handle](docs/src/guides/migrate-velo-handle.md).
Velo 0.22.1 deprecates `Velo::anchor_manager()` and `Velo::rendezvous_manager()`, and 0.23.0 removes them. Their methods are on `Velo`, with three new ones: `create_anchor_with_config`, `active_anchor_count`, `renew_reservations`. Also new: `staging_threshold` and the owner's `unregister_data`. See [Move off the manager accessors](docs/src/guides/migrate-manager-accessors.md).
Velo 0.23.0 makes three breaking changes:
- It opens no per-stream listener by default: the messenger mux carries every remote stream. Call `stream_config` or `stream_bind_addr` to serve peers without the mux, or to turn the mux off. See [0.23.0: the per-stream listener is opt-in](docs/src/guides/migrate-services.md#0230-the-per-stream-listener-is-opt-in).
- It removes the `Messenger` front door that 0.22.1 deprecated: `Messenger::builder`, `MessengerBuilder`, the peer, drain and shutdown methods of `Messenger`, and `Velo::graceful_shutdown`. Build and manage an instance through `Velo`. `Velo::shutdown` is the one shutdown. See [Move off the Messenger front door](docs/src/guides/migrate-messenger-front-door.md).
- Each public item has one path. The anchor and rendezvous managers, the wire messages, and `FrameTransport` are no longer public; velo-ext 0.6.0 drops `FrameTransport`, so stream transports are in-tree only. See [Move to the public paths of 0.23.0](docs/src/guides/migrate-public-paths.md).
A send can name its transport, `.transport("uds")`, and then uses it or fails with `TransportChoiceError`. A reply goes back over the transport its request came in on, also for a send that names none. If the responder has the caller registered without that transport, the reply takes the responder's primary transport. A reply over the transport's frame limit fails the call with an error. See [Choose the transport for a send](docs/src/concepts/transports.md#choose-the-transport-for-a-send).
Use `Velo::shutdown(policy)` to close resources and join owned tasks while Tokio keeps running. The instance and its handles stay valid after shutdown, and shutdown does not release them from memory. Accepted requests remain counted until their replies are submitted, including error replies. See [Shutdown and drain](docs/src/concepts/shutdown.md).
Call `Velo::unregister_peer` when a peer leaves. A restarted peer has a new instance id, so without the call a long-lived node keeps state and connections for every peer it ever served. See [Forget a peer](docs/src/concepts/discovery.md#forget-a-peer).
Batched streams give each stream a window of 32 records in flight by default. A larger window lets a saturated consumer node queue a new stream's first record behind every other stream's backlog. See [Change the credit window](docs/src/guides/tune-batched-streaming.md#change-the-credit-window).
## Crates
| Crate | For | Contents |
|---|---|---|
| `velo` | Application authors | The runtime: messaging, streaming, rendezvous, events, queues, discovery, all in-tree transports (TCP, UDS, NATS, gRPC, ZMQ, UCX, QUIC), metrics |
| `velo-ext` | Authors of out-of-tree plugins | The stable trait surface: `Transport`, `PeerDiscovery`, `ServiceDiscovery`, `TransportObservability`, and the types they use |
| `velo-hub-ext` | Programs that speak the hub's wire protocol without the velo runtime | The hub's wire protocol on `velo-ext` alone: paths, request and response bodies, errors, and ids. `velo-hub` re-exports it as `velo_hub::protocol`. Not published yet. |
| `velo-hub` | Authors of a hub service, and programs that use a hub | A hub (`server`): peer and service discovery, registration, and liveness for a velo application, plus hosted extensions. Its etcd store (`etcd`): registrations that survive a hub restart. Its client (`client`): registration, peer and service discovery through the hub, and calls to extensions. Not published yet. |
Application authors depend on `velo` only. `velo-hub` builds one service that is the peer discovery for an application and hosts extensions. It takes the workspace version and requires `velo` and `velo-hub-ext` with a caret on it. See [The hub](docs/src/concepts/hub.md), [Workspace crates](docs/src/development/architecture.md), and [Versioning](docs/src/development/versioning.md).
Streams to one peer can share its connection through the messenger mux. What the mux costs a serving frontend, and how that was measured, is in [Response-plane performance](docs/src/operations/response-plane-performance.md). Under a linger window, a batch can also go once every live stream on its lane has a record in it, or once it reaches a set size. See [Ending the window early](docs/src/concepts/batched-streaming.md#ending-the-window-early).
QUIC and TCP can keep several lanes, each its own connection, to one peer. See [TCP lanes](docs/src/concepts/transports.md#tcp-lanes) and [QUIC lanes](docs/src/operations/quic-performance.md#lanes).
Streams through the mux spread over those lanes, and each stream stays on one lane. If the caller gives a key (`attach_anchor_keyed`, `prebind_anchor_keyed`), the receiver places the stream by that key, so streams with one key to one receiver share a lane. The key is a placement hint: the mux never orders records across streams. Without a key, the receiver uses the lane with the least load. See [Lanes](docs/src/concepts/batched-streaming.md#lanes).
A stream item larger than the eager limit (256 KiB by default) goes through rendezvous, outside the order of its lane. A stream can therefore end, and free its mux slot, before the receiver has its last large item. The receiver keeps that stream open by its full slot id until the item arrives, and the next stream on that slot opens at once. See [Ordering is per slot](docs/src/concepts/batched-streaming.md#ordering-is-per-slot).
A payload that goes through rendezvous states its own size, and the receiver allocates that size before it reads a byte. `VeloBuilder::staged_payload_max` sets the largest one a node takes. A larger one is refused before anything of its size is allocated: a request gets an error that names both sizes, and a stream item ends its own stream with that error while other streams go on. See [The receiver's limit](docs/src/concepts/rendezvous.md#the-receivers-limit).
A staged payload is freed when its last reference and its last reader are both gone, whichever goes last. An owner drops its reference with `Velo::unregister_data`, which is synchronous and safe to call from `Drop`. If a reader still holds a lease, the reader's detach, release, or reaped lease then frees it. See [When a slot is freed](docs/src/concepts/rendezvous.md#when-a-slot-is-freed).
The local ID in an anchor handle is random. The handle is all that a peer needs to attach to an anchor or open its mux slot, and velo does not authenticate peers, so a host that can reach a node cannot guess the handle of another request's stream. See [Streaming](docs/src/concepts/streaming.md).
Build with `default-features = false` to omit distributed events, work queues, and built-in discovery services. The default `services` feature keeps those APIs available. See [Services and stream transports](docs/src/guides/migrate-services.md).
## Quick start
```bash
cargo add velo
cargo add serde --features derive
cargo add tokio --features macros,rt-multi-thread
cargo add anyhow
```
```rust
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use velo::transports::tcp::TcpTransportBuilder;
use velo::{Handler, TypedContext, Velo};
#[derive(Serialize, Deserialize)]
struct AddRequest { a: i64, b: i64 }
#[derive(Serialize, Deserialize)]
struct AddResponse { sum: i64 }
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let node_a = Velo::builder()
.add_transport(Arc::new(TcpTransportBuilder::new().build()?))
.build()
.await?;
let node_b = Velo::builder()
.add_transport(Arc::new(TcpTransportBuilder::new().build()?))
.build()
.await?;
node_b.register_handler(
Handler::typed_unary_async("add", |ctx: TypedContext<AddRequest>| async move {
Ok(AddResponse { sum: ctx.input.a + ctx.input.b })
})
.build(),
)?;
node_a.register_peer(node_b.peer_info())?;
let resp: AddResponse = node_a
.typed_unary::<AddResponse>("add")?
.payload(&AddRequest { a: 3, b: 4 })?
.instance(node_b.instance_id())
.send()
.await?;
assert_eq!(resp.sum, 7);
Ok(())
}
```
See [Getting started](docs/src/guides/getting-started.md) for the feature flags.
Stream reservations default to 120 seconds before ordinary attachment and 180 seconds for a messenger-mux bind to receive its first batch. `VeloBuilder::reservation_config` configures these lifetimes. Applications can batch held reservations through `Velo::renew_reservations`; see [reservation renewal](docs/src/concepts/streaming.md#reservation-renewal).
## Build and test
```bash
cargo build --all-features
cargo test --all-features --all-targets # NATS on localhost:4222 and etcd on :2379 for those tests
cargo test --all-features --doc -p velo -p velo-ext -p velo-hub -p velo-hub-ext # --all-targets leaves out doctests
cargo clippy --all-features --no-deps --all-targets -- -D warnings
cargo fmt --check
cargo machete
bash scripts/check-semver.sh
bash scripts/build-book.sh # needs mdbook, mdbook-mermaid, mdbook-linkcheck
```
The `zmq` feature needs `cmake`. The `ucx` feature needs the `libibverbs-dev` and `librdmacm-dev` headers. See [Testing](docs/src/development/testing.md).
A change on a hot path also needs a test that counts its cost. See [Review for performance](docs/src/development/performance-review.md).
On macOS the whole workspace builds with `--all-features`, but the `ucx` transport is Linux only. See [Platforms](docs/src/guides/getting-started.md#platforms).
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) and [Documentation](docs/src/development/documentation.md).