Skip to content

System Architecture

Monibuca V6 is a high-performance streaming media server engine written in Rust. This article introduces its overall architecture design.

View full-screen architecture diagram →

┌─────────────────────────────────────────────────────────────────┐
│ Monibuca Engine │
│ │
│ ┌──────────┐ ┌─────────────────┐ ┌───────────────────┐ │
│ │ Protocol │ │ StreamManager │ │ PluginManager │ │
│ │ Plugins │───▶│ │◀───│ │ │
│ │ (RTMP, │ │ ┌───────────┐ │ │ init / start / │ │
│ │ RTSP, │ │ │ Registry │ │ │ stop / reload │ │
│ │ HLS, │ │ └───────────┘ │ └───────────────────┘ │
│ │ WebRTC, │ │ ┌───────────┐ │ ┌───────────────────┐ │
│ │ SRT...) │ │ │ Lifecycle │ │ │ EngineContext │ │
│ └──────────┘ │ └───────────┘ │ │ (IoC Container) │ │
│ │ ┌───────────┐ │ └───────────────────┘ │
│ │ │ WaitQueue │ │ │
│ │ └───────────┘ │ ┌───────────────────┐ │
│ └────────┬────────┘ │ ConfigManager │ │
│ │ │ (YAML + API) │ │
│ ▼ └───────────────────┘ │
│ ┌─────────────────────────────────────┐ │
│ │ Stream Instance │ │
│ │ │ │
│ │ Publisher ──▶ RingBuffer ──▶ Dispatcher ──▶ Subs │
│ │ │ │ │ │
│ │ VideoTrack AudioTrack DispatcherPool │
│ └─────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Publisher (Ingest)
StreamManager.create_publisher(stream_path)
├──▶ VideoTrack ──▶ RingBuffer (256 slots, lock-free)
│ │
├──▶ AudioTrack ──▶ RingBuffer (64 slots, lock-free)
│ │
│ ▼
│ Dispatcher / DispatcherPool
│ │ │ │
│ ▼ ▼ ▼
│ Queue 1 Queue 2 Queue N
│ (bounded) (bounded) (bounded)
│ │ │ │
└──▶ WaitQueue ▼ ▼ ▼
(Wait List) Subscriber Subscriber Subscriber
(Playback) (Playback) (Playback)

The core modules are located in src/core/ and are responsible for the underlying data structures and processing logic of the streaming engine:

ModuleFileResponsibility
bufferbuffer.rsLock-free SPMC ring buffer for frame storage
frameframe.rsAVFrame audio/video frame data structure
tracktrack.rsAudio/video track management (VideoTrack / AudioTrack)
publisherpublisher.rsPublisher, manages tracks and subscriber list
subscribersubscriber.rsSubscriber, consumes frame data from RingBuffer
dispatcherdispatcher.rsFrame dispatcher, single read broadcasts to all subscribers
poolpool.rsObject pool (BytesPool, ObjectPool, ThreadLocal pool)
tasktask.rsHierarchical task system with cascading cancellation
proxyproxy.rsPull/Push proxy (Pull Proxy / Push Proxy)
recorderrecorder.rsStream recording framework (FLV / MP4 / fMP4 / HLS)
transformertransformer.rsStream transformer (subscribe source → process → publish new stream)
playbackplayback.rsPlayback speed control and timestamp scaling
storagestorage.rsAsync storage trait (io_uring ready)

Monibuca V6 uses a Cargo Workspace to organize code, split into multiple independent crates:

monibuca/ # Main crate (engine + binary)
├── src/
│ ├── core/ # Core data structures
│ ├── manager/ # StreamManager / PluginManager
│ ├── config/ # Configuration management
│ ├── grpc/ # gRPC API
│ └── room/ # Built-in room service
├── crates/
│ ├── monibuca-codec/ # codec crate — codecs + enums + traits
│ ├── monibuca-sdk/ # SDK crate — plugin development SDK
│ ├── monibuca-sdk-macros/ # SDK proc macros
│ ├── m7s-config-framework/ # Configuration framework
│ └── m7s-config-macros/ # Configuration framework macros
└── plugins/ # 25 plugin crates
├── rtmp/
├── rtsp/
├── flv/
├── hls/
├── webrtc/
└── ...
monibuca-codec ◀── Bottom layer, zero dependencies on other monibuca crates
monibuca-sdk ◀── The sole contract layer for plugin development
monibuca (engine) ◀── Main engine crate
plugins/* ◀── All plugins depend only on the SDK
  • codec: Defines all shared types — AVFrame, VideoCodec, AudioCodec, VideoFrameType, trait interfaces (PublisherApi / SubscriberApi / StreamManagerApi)
  • SDK: Wraps codec and provides plugin registration, HTTP routing, config schema, and other development tools
  • Main crate: Engine implementation, containing core logic such as StreamManager, Dispatcher, RingBuffer, etc.
  • plugins/: Protocol and feature plugins, depending only on the SDK crate

Monibuca V6 supports three plugin loading modes:

ModeFeature FlagCharacteristics
Static compilationstatic-pluginsLinked at compile time, best performance, default mode
Dynamic loadingdynamic-plugins.so/.dylib/.dll loaded at runtime
WASM sandboxIsolated execution, highest security

Static plugins are selectively compiled via Cargo Feature Flags:

Cargo.toml
[features]
default = ["static-plugins"]
rtmp = ["dep:plugin-rtmp"]
rtsp = ["dep:plugin-rtsp"]
webrtc = ["dep:plugin-webrtc"]
all-plugins = ["rtmp", "rtsp", "flv", "hls", "webrtc", "srt", ...] # default full set (no rsmpeg)
all-plugins-rsmpeg = ["all-plugins", "rsmpeg"] # full set with FFmpeg library bindings
ComponentLibraryPurpose
Async runtimeTokioEvent-driven concurrency
Mutexparking_lotHigh-performance Mutex / RwLock
Concurrent hash mapDashMapLock-free stream registry
Atomic pointer swapArcSwapLock-free IDR list, subscriber list
QUIC transportQuinnWebTransport / QUIC protocol support
Zero-copy bytesBytesZero-copy frame data sharing
WebRTCrustrtcWebRTC protocol stack
gRPCTonicAPI service
DatabaseSQLxRecording index, configuration persistence
SerializationSerde + serde_json/serde_yamlConfiguration and API data formats
  1. Lock-free first: RingBuffer write operations use fetch_add atomic instructions, read operations achieve lock-free access through ArcSwap
  2. Zero-copy: Frame data is shared via Arc<AVFrame>, no data copying between subscribers
  3. Single-read broadcast: Dispatcher reads frame data from the RingBuffer only once, then broadcasts to all subscribers
  4. Backpressure control: Uses bounded channels, slow subscribers drop frames instead of blocking other subscribers
  5. Object pool reuse: BytesPool and ThreadLocal pools reduce memory allocation on hot paths