Cloudflare MoQ CDN: Scale Sub-Second Live Streams in 10 Minutes
You have MoQ running on Ant Media Server, and now you need to serve more viewers than one server can handle. Right now every viewer connects to the relay on your server, and that relay is limited by the server's network bandwidth.
A Cloudflare MoQ CDN takes that load off your server. HLS solved the same problem years ago with a CDN. One origin server produces the stream, and the CDN caches it near the viewers and serves it from there. MoQ follows the same pattern, so a Media over QUIC CDN is a network of relays instead of caches.
Cloudflare runs MoQ relays all around the world, and the Ant Media Server MoQ plugin can push to them with one setting change. By the end of this post you will have your stream playing through Cloudflare's relays, and you will know why that scales where a single relay does not.
The setup takes about 10 minutes on a server that already has the plugin. If you do not have it yet, start with the MoQ announcement post or the MoQ on AWS walkthrough.
Table of Contents
- Why does one MoQ relay run out?
- How does the Cloudflare MoQ CDN fan out?
- Set up the Cloudflare MoQ CDN in 10 minutes
- Test it: watch your stream come out of Cloudflare
- What's next once your stream plays from the Cloudflare MoQ CDN?
- Before you build production on it
- Frequently Asked Questions
Why Does One MoQ Relay Run Out?
It runs out of network bandwidth long before it runs out of CPU. Every viewer gets their own QUIC connection, their own encrypted copy of every frame, and their own retransmissions when their Wi-Fi drops a packet. Nothing in that list gets cheaper as the audience grows. The thousandth viewer costs the relay as much as the first one did.
A 1 Gbps port can feed about 330 viewers of a 1080p stream at 3 Mbps, and a 10 Gbps port about 3,300. Adding a 720p rendition does not change that. The server then encodes and sends two streams, and every viewer still uses their own share of the bandwidth. A bigger instance does not move that ceiling by much.
The second limit is distance. Say a viewer sits 150 ms away from your server. Every lost packet takes a 150 ms round trip to recover, and the player's jitter buffer grows to cover that. A relay 10 ms from the same viewer recovers the same loss in 10 ms, so the buffer can stay at the player's default of 250 ms.
How Does the Cloudflare MoQ CDN Fan Out?
The CDN keeps one connection per track to your Ant Media Server, no matter how many viewers it serves. Your server publishes each stream to the Cloudflare relay nearest to it. A viewer lands on the relay nearest to them, wherever they are, and that relay pulls the stream across Cloudflare's network once for all of its viewers.
Relays pass the media through without decoding it, so your encoder settings reach the viewer unchanged.
MoQ through a relay CDN gets you WebRTC's delay and HLS's way of scaling. A WebRTC edge holds a session for every viewer, so a bigger audience means more edge nodes. An HLS CDN carries the audience for you, but it caches segments, so viewers watch seconds behind. A MoQ relay holds one subscription per track and passes each frame on as it arrives, so it has neither problem.
It is still in beta, so run the embedded relay until the server's bandwidth is the limit, then add the CDN URL.
What Does the Plugin Do With a CDN URL?
It publishes every stream twice. Setting moqCdnUrl adds a second destination, it does not replace the embedded relay. For every stream, and every ABR rendition of it, the plugin starts one extra moq process that sends the already encoded frames to the CDN.
Nothing is re-encoded, and the broadcast names are the same on both ends:
live/studio1/sourcelive/studio1/720p
Everything else is untouched: ingest, playback from your own server, recording, HLS and WebRTC. If the connection to Cloudflare stalls, only the CDN copy drops frames. Viewers on your own relay never notice.
Publish to your server, never to Cloudflare. The CDN only delivers streams to viewers. The browser publisher, OBS and every other source still connect to your Ant Media Server, and the plugin forwards the stream to Cloudflare.
The plugin verifies Cloudflare's TLS certificate. Only the local connection to your embedded relay, which uses a self-signed certificate, skips that check.
Set Up the Cloudflare MoQ CDN in 10 Minutes
You need Ant Media Server 3.0.0 or later with the 3.1.0 release of the MoQ plugin installed, and HTTPS on. On a new AWS instance, the MoQ on AWS post gets you there in four steps. On a server you already run, follow the MoQ docs page. You also need a Cloudflare account. Cloudflare's MoQ docs cover the relay side in more detail than this post does.
Create a Relay in Cloudflare
In the Cloudflare dashboard go to Media > Realtime > MoQ Relay, select Create relay, give it a name and confirm. You get two tokens, a publish token for your server and a subscribe token for your viewers. They are shown once and Cloudflare does not store them, so copy both now. You can also create relays through Cloudflare's API.
The publish token is the whole URL the server will use.
Give the Publish Token to the Plugin
Open your application in the web panel, go to Settings > Advanced, and add the key inside customSettings:
{
"customSettings": {
"plugin.moq": {
"moqCdnUrl": "https://draft-16.cloudflare.mediaoverquic.com/<PUBLISH_TOKEN>"
}
}
}
Save, then restart the application so the plugin picks up the new setting. The host has to be draft-16. A draft-14 host is the trap: it accepts the publish and the logs look healthy, but no viewer can ever find the stream.
The next stream that starts writes this line to /usr/local/antmedia/log/ant-media-server.log:
MoQ: 2 muxer(s) publishing for stream studio1, with CDN: true
A stream without ABR renditions gets two muxers, one for your relay and one for Cloudflare.
One key under customSettings is the whole Cloudflare MoQ CDN configuration.
Test It: Watch Your Stream Come Out of Cloudflare
Now the fun part. Start a stream on your server the way you already do. The plugin's browser publisher at https://your-domain:5443/live/moq/publish.html is the quickest, and OBS, SRT, WHIP or an IP camera work just as well. Call it studio1.
Use Chrome for this test. Chrome, Edge and Safari 26.4 or later play MoQ, but Firefox is still unstable for it.
Open the plugin's player with your subscribe token as the url parameter:
https://your-domain:5443/live/moq/play.html?url=https://draft-16.cloudflare.mediaoverquic.com/&name=live/studio1/source
Done. The page loads from your server, but the media now comes from the Cloudflare relay nearest to you. Send the link to a friend on another continent. Their copy comes from a relay near them, and your server still sends Cloudflare just one copy.
The quality buttons stay empty on Cloudflare hosts, because the player turns off stream discovery there. To watch a rendition, change name in the URL, for example to live/studio1/720p.
The debug panel under the video shows frame rate and buffer. Set the player beside the source going in, and the two timecodes stay within a fraction of a second of each other. That small gap is what Cloudflare's path adds for your viewers.
What's Next Once Your Stream Plays From the Cloudflare MoQ CDN?
Your server now sends each track out once, and Cloudflare carries it to every viewer, wherever they are. The 330-viewer ceiling of a 1 Gbps port no longer caps your audience, and in the side-by-side test the Cloudflare copy stays within a fraction of a second of the source.
If your origin is still a test box, the AWS deployment guide gets a fresh MoQ origin running in four steps, and the same moqCdnUrl setting works there unchanged.
To prove the whole path on your own stream before you commit, from ingest through the embedded relay to the Cloudflare relays nearest your viewers, install the plugin on a MoQ test server under the 14-day Ant Media Server Enterprise Edition trial. No credit card is required, and you can watch your server's outbound bandwidth stay flat while viewers join through Cloudflare.
Before You Build Production on It
Check these five limits before you send real viewers through Cloudflare:
- Cloudflare's relays are in beta, with no SLA published, and Cloudflare says the API may change.
- Only the draft-16 host works with the plugin today. Cloudflare already recommends draft-18 for new deployments and keeps draft-16 open for existing clients. MoQ is still an IETF draft, so expect version bumps on every side, including a new Cloudflare hostname.
- One subscribe token serves all viewers. Per-viewer playback auth through Ant Media Server play tokens is designed but not shipped yet.
- A viewer who joins late starts at the live edge, because Cloudflare's relays do not offer rewind yet.
- Viewers need Chrome, Edge, Brave or Safari 26.4 or later. Firefox has WebTransport, but the plugin docs list it as unstable for MoQ playback.
Comments
No comments yet. Start the discussion.