« All posts

Monocoque: A Pure-Rust ZMTP 3.1 (ZeroMQ) Messaging Library

Monocoque is a pure-Rust ZMTP 3.1 ZeroMQ library with io_uring, tokio, and smol backends, beating libzmq on throughput and latency in benchmarks.

Monocoque is a ZeroMQ-compatible messaging library implemented from scratch in Rust, speaking ZMTP 3.1 directly rather than binding to libzmq. It defaults to io_uring via compio but also supports tokio and smol backends behind a shared runtime facade, interoperating with any existing libzmq peer while staying entirely within Rust's memory-safety model.

The library covers all 11 ZeroMQ socket types (REQ/REP, DEALER/ROUTER, PUB/SUB, PUSH/PULL, PAIR), PLAIN/CURVE authentication, automatic reconnection, and ZMTP heartbeating. It adds performance-oriented APIs such as opt-in write coalescing, vectored writes for large frames, allocation-free receive buffers, and zero-copy message passing via Bytes.

Benchmarked against rust-zmq (FFI bindings to libzmq) on loopback TCP, all three backends beat libzmq by 2-4x on small-message throughput once coalescing is enabled, and REQ/REP latency runs 2.6-3.9x lower across the board. Single-connection loopback tests favor the epoll-based tokio/smol backends, since io_uring's real advantages emerge under high connection counts and batched submission — a relevant data point for teams evaluating native, unsafe-free ZeroMQ alternatives in Rust.