Overview
IronSBE is a complete Rust implementation of the Simple Binary Encoding (SBE) protocol, designed for ultra-low-latency financial systems. It provides both server and client capabilities with a focus on performance, type safety, and ease of use.
SBE is the binary encoding standard used by major exchanges including CME, Eurex, LSE, NASDAQ, and Binance for market data feeds and order entry systems.
Key Features
- Zero-copy decoding - Direct buffer access with compile-time offset calculation
- Schema-driven code generation - Type-safe messages from XML specifications
- Sub-microsecond latency - Cache-friendly memory layouts with aligned buffers
- Multi-transport support - TCP, UDP unicast/multicast, shared memory IPC
- A/B feed arbitration - First-arrival-wins deduplication for redundant feeds
- Market data patterns - Order book management, gap detection, snapshot recovery
- 100% safe Rust - No unsafe code in core library
- Async/await support - Built on Tokio for high-performance async I/O
Performance
Benchmarked on Apple M4 Max 64GB, macOS Tahoe 26.2:
| Operation | Latency (p50) | Latency (p99) | Throughput |
|---|---|---|---|
| Encode NewOrderSingle | 3 ns | 4 ns | 342.8M msg/sec |
| Decode NewOrderSingle | 1 ns | 1 ns | 1262.6M msg/sec |
| Encode MarketData (10 entries) | 6 ns | 8 ns | 165.5M msg/sec |
| Decode MarketData (10 entries) | 0 ns | 1 ns | 2178.6M msg/sec |
| SPSC channel send | 2 ns | 2 ns | 648.5M msg/sec |
| MPSC channel send | 7 ns | 9 ns | 145.5M msg/sec |
| TCP round-trip (localhost) | 16.8 μs | 23.7 μs | 60K msg/sec |
Run your own benchmarks:
Quick Start
Installation
Add IronSBE to your Cargo.toml:
[]
= "0.1"
[]
= "0.1"
Define Your Schema
Create an SBE schema file (schemas/trading.xml):
1
2
Generate Code
Add to your build.rs:
Encode Messages
use *;
// Include generated code
use ;
Decode Messages
use *;
use ;
Architecture
graph TB
subgraph Application["Application Layer"]
Server["Server Engine"]
Client["Client Engine"]
MarketData["Market Data Handler"]
end
subgraph Channel["Channel Layer"]
SPSC["SPSC<br/>~20 ns"]
MPSC["MPSC<br/>~100 ns"]
Broadcast["Broadcast<br/>1-to-N"]
end
subgraph Transport["Transport Layer"]
TCP["TCP<br/>Tokio"]
UDP["UDP<br/>Unicast"]
Multicast["Multicast<br/>A/B"]
IPC["IPC<br/>SHM"]
end
subgraph Codec["Codec Layer"]
Encoders["Generated Encoders / Decoders<br/>Zero-copy, compile-time offsets, type-safe"]
Core["ironsbe-core<br/>Buffer traits, headers, primitives"]
end
Server --> SPSC
Server --> MPSC
Client --> SPSC
Client --> MPSC
MarketData --> Broadcast
SPSC --> TCP
SPSC --> UDP
MPSC --> TCP
MPSC --> Multicast
Broadcast --> Multicast
Broadcast --> IPC
TCP --> Encoders
UDP --> Encoders
Multicast --> Encoders
IPC --> Encoders
Encoders --> Core
Crate Structure
IronSBE is organized as a Cargo workspace with 11 crates:
| Crate | Description |
|---|---|
ironsbe |
Facade crate re-exporting public API |
ironsbe-core |
Buffer traits, message headers, primitive types, encoder/decoder traits |
ironsbe-schema |
SBE XML schema parser and validation |
ironsbe-codegen |
Build-time Rust code generation from SBE schemas |
ironsbe-derive |
Procedural macros (#[derive(SbeMessage)]) |
ironsbe-channel |
Lock-free SPSC/MPSC/Broadcast channels |
ironsbe-transport |
TCP, UDP unicast/multicast, shared memory IPC |
ironsbe-server |
Async server engine with session management |
ironsbe-client |
Async client with auto-reconnection |
ironsbe-marketdata |
Order book, gap detection, A/B feed arbitration |
ironsbe-bench |
Benchmarks using Criterion |
Dependency Graph
ironsbe (facade)
├── ironsbe-core
├── ironsbe-schema
├── ironsbe-codegen
├── ironsbe-channel
├── ironsbe-transport
├── ironsbe-server
├── ironsbe-client
└── ironsbe-marketdata
ironsbe-server
├── ironsbe-core
├── ironsbe-channel
└── ironsbe-transport
ironsbe-client
├── ironsbe-core
├── ironsbe-channel
└── ironsbe-transport
ironsbe-codegen
├── ironsbe-core
└── ironsbe-schema
Examples
Running the Examples
IronSBE includes working server and client examples:
# Terminal 1: Start the server
&&
# Terminal 2: Run the client
&&
Expected output:
Server:
Starting IronSBE server on 127.0.0.1:9000
[Server] Session 1 connected
[Server] Message #1 from session 1: template_id=101, size=45 bytes
[Server] Message #2 from session 1: template_id=102, size=45 bytes
...
[Server] Session 1 disconnected
Client:
Connecting to IronSBE server at 127.0.0.1:9000
[Client] Connected to server
[Client] Sent message #1
[Client] Received response: 45 bytes
[Client] Response payload: Hello from IronSBE client! Message #1
...
Client stopped
TCP Echo Server
use MessageHeader;
use ServerBuilder;
use ;
use SocketAddr;
use ;
async
TCP Client
use ;
use ;
use MessageHeader;
use SocketAddr;
use Duration;
async
SPSC Channel (Ultra-Low Latency)
use spsc;
Broadcast Channel
use BroadcastChannel;
Supported SBE Features
| Feature | Status |
|---|---|
| Primitive types (int8-64, uint8-64, float, double, char) | ✅ |
| Fixed-length arrays | ✅ |
| Enums | ✅ |
| Bitsets (sets) | ✅ |
| Composite types | ✅ |
| Repeating groups | ✅ |
| Nested repeating groups | ✅ |
| Variable-length data | ✅ |
| Optional fields (null values) | ✅ |
| Schema versioning | ✅ |
| Little-endian byte order | ✅ |
| Big-endian byte order | ✅ |
| Message header customization | ✅ |
| Constant fields | ✅ |
System Requirements
Minimum
- Rust 1.75+
- Linux, macOS, or Windows
Recommended for Production
- Linux kernel 5.10+ (for io_uring support)
- CPU with AVX2 support
- Dedicated CPU cores (isolcpus)
- 10GbE+ network interface
- Kernel bypass capable NIC (optional)
System Tuning
# CPU performance mode
|
# Network tuning
# NIC tuning (disable interrupt coalescing)
Documentation
Development
Prerequisites
- Rust 1.85+ (Edition 2024)
- Cargo
Building
# Build all crates
# Run tests
# Run linting
# Format code
# Generate documentation
Using the Makefile
The project includes a comprehensive Makefile:
# Format and lint
# Run tests
# Pre-push checks (recommended before committing)
# Run benchmarks
# Generate documentation
# Set version across all crates
# Publish all crates to crates.io (in dependency order)
Running Examples
# Run the server example
&&
# Run the client example (in another terminal)
&&
Code Style
- Follow Rust standard formatting (
cargo fmt) - Pass all clippy lints (
cargo clippy -- -D warnings) - Add tests for new functionality
- Update documentation for API changes
- All comments and documentation in English
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and ensure that the project still builds and all tests pass
- Run
make pre-pushto verify everything works - Commit your changes and push your branch to your forked repository
- Submit a pull request to the main repository
Contact
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
- Author: Joaquín Béjar García
- Email: jb@taunais.com
- Telegram: @joaquin_bejar
- Repository: https://github.com/joaquinbejar/IronSBE
- Documentation: https://docs.rs/ironsbe
License
This project is licensed under the MIT License - see the LICENSE file for details.