zus-rs: ZUS RPC Framework for Rust
ZUS-RS is a high-performance, cross-language RPC framework for Rust with compatibility for Java and C++ implementations. It provides service discovery via ZooServer and supports QuickLZ/Snappy compression.
Features
- β¨ Cross-Language RPC: Wire-compatible with Java and C++ implementations
- π High Performance: Built on Tokio async runtime
- π¦ Protocol Buffer: Efficient binary serialization
- ποΈ Compression: QuickLZ (default) and Snappy support with smart params-only compression
- π Service Discovery: Integration with ZooServer for dynamic service lookup
- π‘οΈ Type Safe: Full Rust type safety with protobuf definitions
- π Production Ready: Tested with comprehensive cross-language test suite
Quick Start
Installation
Add zus-rs to your Cargo.toml:
[]
= "1.1.4"
= { = "1.35", = ["full"] }
Or choose specific features:
# Just client
[]
= { = "1.1.4", = ["client"] }
# Just server
[]
= { = "1.1.4", = ["server"] }
# Protocol only (no RPC runtime)
[]
= { = "1.1.4", = ["protocol"] }
Usage Patterns
ZUS-RS supports two connection styles, matching the C++ and Java implementations:
Style 1: Direct Connection (Without ZooServer)
- Use when: You know the exact service address (development, simple deployments)
- Address format:
tcp://host:portortcp://host1:port1,host2:port2(comma-separated for multiple endpoints) - No service discovery: You manage service addresses manually
Style 2: ZooServer-Based Discovery (With ZooServer)
- Use when: You need dynamic service discovery, load balancing, and automatic failover (production)
- Address format:
zns://zooserver:port/service/path/ - Automatic features: Service discovery, health checks (every 3s), round-robin load balancing
Client Example - Direct Connection (Style 1)
use Bytes;
use RpcClient;
async
Client Example - ZooServer Discovery (Style 2)
use Bytes;
use RpcClient;
async
Server Example - Direct TCP (Style 1)
use Bytes;
use Arc;
use ;
;
async
Server Example - With ZooServer Registration (Style 2)
use Bytes;
use Arc;
use ;
use ZusZooClient;
;
async
Running ZooServer (Standalone)
To use Style 2 (ZooServer-based discovery), you need a running ZooServer instance. ZUS-RS includes a production-ready ZooServer implementation.
Quick Start
# Run with default settings (binds to 0.0.0.0:9528)
# Run with a config file
# Run with debug logging
RUST_LOG=debug
Configuration File
Create a .cfg file to customize ZooServer:
[zusnet]
# Maximum concurrent connections (default: 1000)
maxconnects=1000
# Idle connection timeout in seconds (default: 60)
idleconntimeout=60
# Enable compression (default: true)
COMPRESS=true
# Compression threshold in bytes (default: 4096)
COMPRESS_THRESHSIZE=4096
[zooserver]
# Server listening port (default: 9528)
srvport=9528
Example: Full Setup with ZooServer
# Terminal 1: Start ZooServer
# Terminal 2: Start your service (registers with ZooServer)
# Terminal 3: Run client (discovers service via ZooServer)
ZooServer Features
- Service Discovery: Services register at paths like
/zus/services/myservice/tcp:host:port - Ephemeral Nodes: Auto-cleanup when services disconnect
- Distributed Locking: Path-based distributed locks
- Session Management: Automatic timeout (default: 10s)
- Health Monitoring: Clients send periodic heartbeats via
SyncPath
For more details, see zooserver/README.md.
Feature Flags
Choose the features you need to minimize dependencies:
| Feature | Description | Use Case |
|---|---|---|
default |
Client + Server + Protocol | Full-featured applications |
minimal |
Protocol definitions only | Message definitions for FFI |
protocol |
Protocol + Codec + Compression | Custom transport layer |
client |
RPC client functionality | Client applications |
server |
RPC server functionality | Service implementations |
full |
Everything | Development and testing |
Examples
# Microservice (server only)
[]
= { = "1.1.4", = ["server"] }
# Client application
[]
= { = "1.1.4", = ["client"] }
# Protocol implementation (custom transport)
[]
= { = "1.1.4", = ["protocol"] }
# Minimal (just message definitions)
[]
= { = "1.1.4", = ["minimal"] }
Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β zus-rs (convenience) β
β Feature flags: minimal, protocol, client, serverβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β β β
β β β
βββββββββββ βββββββββββ ββββββββββββ
β client β β server β β protocol β
β feature β β feature β β feature β
βββββββββββ βββββββββββ ββββββββββββ
β β β
ββββββββββββββββΌβββββββββββββββ
β
ββββββββββββββββββββββββββββββββ
β zus-rpc-{client,server} β
β zus-discovery (ZooServer) β
β zus-common (codec/compress) β
β zus-proto (protobuf msgs) β
ββββββββββββββββββββββββββββββββ
Module Organization
use proto; // Protocol Buffer definitions (always available)
use common; // Codec and compression (protocol feature)
use discovery; // ZooServer client (client/server features)
use client; // RPC client (client feature)
use server; // RPC server (server feature)
// Or use the prelude for common imports
use *;
Cross-Language Compatibility
ZUS-RS is wire-compatible with Java and C++ implementations:
- β Java: Full compatibility tested with integration tests
- β C++: Production-tested compatibility
- β Protocol: Same 40-byte RPC header format
- β Compression: Same QuickLZ/Snappy algorithms
- β Validation: Same CRC16/CRC32 checksums
Compression Strategy
ZUS-RS implements params-only compression for requests to match Java's decoder architecture:
- Requests: Method name stays uncompressed, only params data is compressed
- Responses: Full body compression
- Threshold: 4096 bytes (4KB) default, configurable
- Algorithms: QuickLZ Level 1 (default), Snappy fallback
This ensures perfect cross-language compatibility:
β
Java Client β Rust Server
β
Rust Client β Java Server
β
C++ Client β Rust Server
β
Rust Client β C++ Server
Address Format Reference
Direct Connection (tcp://)
Single endpoint: tcp://host:port
Multiple endpoints: tcp://host1:port1,host2:port2,host3:port3
Examples:
tcp://localhost:9527tcp://192.168.1.10:9527tcp://service1.example.com:9527,service2.example.com:9527
ZooServer Discovery (zns://)
Format: zns://zooserver1:port1[,zooserver2:port2]/service/path/
Examples:
zns://localhost:9528/zus/services/myservice/zns://zoo1:2181,zoo2:2181/zus/services/myservice/zns://10.0.1.1:2181/zus/services/echo/
Note: The service path should end with / and correspond to where servers register themselves in ZooServer.
Performance
- Throughput: ~100K requests/sec (localhost, no compression)
- Latency: < 1ms p99 (localhost)
- Compression Ratio: ~70% reduction (5440 bytes β 477 bytes typical)
- Memory: Low overhead with zero-copy where possible
Examples
See zus-examples/ for complete examples:
- Simple Client: Basic RPC calls (
example-client) - Simple Server: Service implementation (
example-server) - Telemetry Server: Server with OpenTelemetry integration (
example-server-telemetry) - ZooServer Discovery: Service registration and discovery
- Cross-Language: Interoperability with Java/C++
Testing
Run tests for all feature combinations:
# Test default features
# Test minimal features
# Test client only
# Test server only
# Test all features
Documentation
- Getting Started Guide
- Protocol Specification
- ZooServer Architecture
- Cross-Language Tests
- Repository Organization
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Credits
Developed by the ZUS Rust Team as a modern, cross-language compatible RPC framework.
Version: 1.1.4 Last Updated: 2026-01-21 Status: Production Ready