Architecture
Moq is designed as a layered protocol stack where each layer has a specific responsibility. This separation of concerns makes the system flexible, scalable, and easy to reason about.The Fundamental Rule
This architectural constraint ensures:- Scalability: CDN logic stays simple and fast
- Security: Content can be fully encrypted without CDN access
- Flexibility: Applications can evolve without changing infrastructure
- Simplicity: Relay servers operate on generic rules, not media-specific logic
The Protocol Stack
Moq consists of multiple protocol layers, each building on the previous:Layer 1: QUIC / WebTransport
The foundation layer handles all networking:- QUIC: Modern transport protocol with built-in encryption, multiplexing, and congestion control
- WebTransport: QUIC-over-HTTP/3 for browser compatibility
- Benefits: Stream multiplexing, 0-RTT connections, partial reliability
- Browsers (native WebTransport support)
- Quinn, Quiche, or other QUIC libraries (native applications)
- The
web-transportcrates (Rust)
Layer 2: moq-lite
The generic pub/sub protocol that operates on structured data without understanding media:- Origin: A collection of broadcasts, produced by one or more sessions
- Broadcast: A collection of tracks, produced by a single publisher
- Track: A collection of groups, delivered out-of-order until expired
- Group: A collection of frames, delivered in-order until cancelled
- Frame: Chunks of data with an upfront size
- Generic: Works with any live data (media, chat, telemetry, etc.)
- Efficient: Built-in deduplication and concurrency
- Flexible: Supports multiple delivery patterns via track/group metadata
- Simple: CDN operates solely on header information
Think of moq-lite as HTTP for live data - it doesn’t care what you’re streaming, just how to deliver it efficiently.
Layer 3: hang
The media-specific layer that handles codecs and containers:- Catalog: A JSON track describing available tracks and their codec properties
- Container: Wraps codec bitstreams with timestamps
- WebCodecs integration: Direct compatibility with browser encoding/decoding APIs
Think of hang as HLS/DASH for Moq - it defines how media is packaged, while moq-lite is the HTTP that delivers it.
Layer 4: Application
Your business logic and application-specific features:- Authentication: Who can publish or subscribe to which broadcasts
- Custom tracks: Chat, telemetry, metadata, or other non-media data
- User interface: Web components, mobile apps, or native applications
- Analytics: Track usage, quality metrics, engagement
Data Flow
Here’s how data flows through the stack when streaming video:Publisher encodes media
Using WebCodecs (browser) or FFmpeg (native), video frames are encoded into codec bitstreams (H.264, AV1, etc.)
hang packages frames
Each encoded frame is wrapped with timing information and packaged according to the hang container format
moq-lite publishes
Frames are organized into tracks and groups, then published through a moq-lite session to the relay
Relay forwards
The relay receives groups and forwards them to subscribers based on moq-lite metadata (priority, caching rules, etc.)
Design Principles
1. Separation of Concerns
Each layer has a single, well-defined responsibility:- QUIC: Reliable, ordered delivery of bytes
- moq-lite: Pub/sub with prioritization and caching semantics
- hang: Media codec and container handling
- Application: Business logic and user experience
2. Dumb Network, Smart Endpoints
Following the end-to-end principle:- The relay is as simple as possible
- Intelligence lives in publishers and subscribers
- Content can be encrypted end-to-end
- Applications control their own destiny
3. Generic + Specific
The stack provides both:- Generic infrastructure (moq-lite) that works for any data type
- Specialized libraries (hang) for common use cases (media)
- Freedom to build custom solutions at any layer
4. Browser-First
Designed for the modern web:- Native WebTransport support
- WebCodecs integration for encoding/decoding
- Web Components for easy integration
- Progressive enhancement for native applications
Comparison to Other Protocols
| Feature | Moq | HLS/DASH | WebRTC |
|---|---|---|---|
| Latency | Sub-second | 3-30 seconds | Sub-second |
| Scale | Massive (CDN) | Massive (CDN) | Limited (P2P/mesh) |
| Browser Support | WebTransport | Native | Native |
| CDN Friendly | Yes | Yes | No |
| E2E Encryption | Yes | No | Yes |
| Complexity | Medium | Low | High |
Clustering and Scale
Moq relays can form clusters for global distribution:- Root node: Coordinates the cluster, tracks available broadcasts
- Leaf nodes: Accept client connections, forward to/from root
- Dynamic routing: Broadcasts can move between nodes
- Regional optimization: Clients connect to nearest node
Next Steps
moq-lite Protocol
Deep dive into the pub/sub transport layer
hang Media Layer
Learn about media-specific encoding and containers
Use Cases
Explore what you can build with Moq
Publishing Guide
Start publishing your own content