xRPC-rs
Async RPC and local IPC library for Rust with transport flexibility.
Start with in-process channels, move to shared memory or Unix sockets for local IPC, and use TCP for network deployment—with the same layered interface.
Status: Actively developed. Core features are available, and the API may change between releases.
Quick Start
This single-process example uses an in-process channel pair. The same RPC layer can run over shared memory, Unix sockets, or TCP by replacing the frame transport.
use ;
use ;
async
Calling try_start() is required before making RPCs. Retaining its handle is optional for ordinary calls, but it enables explicit receive-task joining and forced shutdown. This example retains it for strict cleanup confirmation.
Installation
[]
= "0.3.0"
= { = "1", = ["derive"] }
= { = "1", = ["macros", "rt-multi-thread"] }
To enable an optional codec, replace the xrpc-rs dependency above with, for example:
= { = "0.3.0", = ["codec-messagepack"] }
Available codec features are codec-messagepack, codec-cbor, codec-postcard, and codec-all. Bincode and JSON support are available without optional features.
xrpc-rs 0.3 requires Rust 1.85 or newer.
Status
| Feature | Status |
|---|---|
| FrameTransport Layer (TCP, Unix, SharedMemory, Channel, Arc) | ✅ Completed |
| MessageChannel with compression | ✅ Completed |
| RPC Client/Server | ✅ Completed |
| Streaming | ✅ Completed |
| Connection Pooling | ✅ Completed |
| Service Discovery & Load Balancing | ✅ Completed |
| Docs & Examples | In Progress |
| Python Bindings | Under Consideration |
Architecture
xRPC follows a layered architecture:
| Layer | Trait/Module | Description |
|---|---|---|
| Layer 1 | FrameTransport |
Low-level byte transmission with framing |
| Layer 2 | MessageChannel |
Message-aware channel with compression |
| Layer 3 | RpcClient/RpcServer |
RPC with method dispatch, streaming |
| Layer 4 | LoadBalancer |
Service discovery, load balancing |
Application
↓
LoadBalancedClient (Layer 4)
↓
RpcClient/RpcServer (Layer 3)
↓
MessageChannel (Layer 2)
↓
FrameTransport (Layer 1)
↓
Network/IPC
Transport Comparison
| Transport | Use Case | Cross-Process | Serialization |
|---|---|---|---|
SharedMemoryFrameTransport |
Cross-process local IPC, one client per named server | Yes | Yes |
TcpFrameTransport |
Network / Remote | Yes | Yes |
UnixFrameTransport |
Local IPC (Unix) | Yes | Yes |
ChannelFrameTransport |
Same-process / Testing | No | Yes |
ArcFrameTransport |
Same-process fast path | No | Frame/RPC: Yes; ZeroCopyTransport: No |
Load Balancing
Distribute requests across multiple server instances:
use ;
use async_trait;
use Arc;
;
// Setup load balancer
let endpoints = vec!;
let discovery = new;
let lb = new;
let client = new;
client.init.await?;
// Calls are distributed across servers. Setup failures can fail over before invocation.
let response: Response = client.call.await?;
client.close.await?;
Strategies: RoundRobin, Random, LeastConnections, WeightedRoundRobin, ScoreBased
Features:
- Failover for endpoint selection, connection creation, and startup failures
- No automatic retry after RPC invocation, preventing duplicate non-idempotent calls
- Stream affinity (streaming calls stay on same server)
- Failure-based health tracking with configurable thresholds
- DNS-based discovery; periodic refresh and discovery watching are started explicitly
Documentation
Reference
- Message Protocol - binary framing and payload encoding
- Client Lifecycle - start, close, join, and forced shutdown
- Transport Shutdown - close and terminal error contract
Migration
- Migrating to 0.3 - lifecycle, error matching, and wire compatibility changes
Planned:
- Transport layer guide
- Client/Server usage guide
- Streaming guide
- Discovery & load balancing guide
- Codec guide (Bincode, JSON, MessagePack, CBOR, Postcard)
- Architecture overview & getting started
Examples
RPC Client/Server
# Terminal 1
# Terminal 2
SharedMemory Transport
# Terminal 1
# Terminal 2
Byte-level Transports
Planned:
examples/load_balancing.rs- Discovery and load-balanced RPCexamples/streaming.rs- Server streaming RPCexamples/compression.rs- LZ4/Zstd compressionexamples/custom_codec.rs- JSON/MessagePack codec usage
Used In
- quant-system — A modular workspace for algorithmic trading — real-time market data, strategy execution, and analysis.
License
MIT License - see LICENSE for details.