DEV Community

Ptr
Ptr

Posted on AI-assisted

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 with relays in place 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.

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. That relay asks Cloudflare's control plane which relay your server is connected to, and pulls the stream from it once for all of its viewers. Relays pass the media through without decoding it, so your encoder settings reach the viewer unchanged.

Here are the three ways to scale one live stream out of Ant Media Server, side by side:

Feature WebRTC edge cluster HLS plus HTTP CDN MoQ plus relay CDN
Delay to the viewer About 0.5 s 8 to 12 s, 3 to 5 s with LL-HLS About 0.5 s
Who runs the edge Your Ant Media Server edge nodes The CDN The CDN, or your Ant Media Server edge nodes
What the edge holds per stream One session per viewer Cached segments One subscription per track
What the edge costs Per edge node Per GB Free in beta, per GB later
Status Production Production Beta

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 the plugin does 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/source, live/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.1.0 or later with 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.

1. Create a relay in Cloudflare

In the Cloudflare dashboard go to 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. The publish token is the whole URL the server will use.

You can also create relays through Cloudflare's API.

2. 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>"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Save. You do not need to restart the server, because the plugin reads this setting every time a stream starts. The host has to be draft-16. The draft-14 host does not work with the plugin. 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
Enter fullscreen mode Exit fullscreen mode

A stream without ABR renditions gets two muxers, one for your relay and one for Cloudflare.

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.

Browser support for MoQ still varies, so use Chrome. 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/<SUBSCRIBE_TOKEN>&name=live/studio1/source
Enter fullscreen mode Exit fullscreen mode

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 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.

Before you build production on it

  • 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. 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.
  • As of 2026, every major browser supports MoQ in one form or another, but we recommend Chrome for the best results.

FAQ

Does MoQ need a CDN?

No. The embedded relay in the plugin serves viewers straight from port 4443, and for an audience in the low hundreds that is the whole setup. A CDN is for the day your bandwidth, or the distance to your viewers, becomes the limit.

Is Cloudflare's MoQ relay free?

Free during the beta, at any scale, with no SLA. Cloudflare's 2025 announcement named 5 cents per GB outbound as the self-serve price at general availability. That is a stated intent from a year ago, not a price list.

Can I use a different MoQ CDN or my own relays?

The setting takes any URL that accepts a MoQ draft-16 publish, so a moq-relay you host or moq.dev's managed service should work in principle. Cloudflare is the one the plugin has been tested against. To replace the embedded relay instead of adding a destination, set useEmbeddedRelay to false and point externalRelayUrl at yours.

Does pushing to the CDN add latency?

Yes, by the length of the extra hops: your server to Cloudflare's nearest relay, that relay to the viewer's relay, and the last mile. The CDN's path sets that number, not the plugin. The side-by-side comparison from the test, on your own stream, gives the number that counts.

Is the subscribe token safe in a public player page?

It is in the URL, so anyone who views the page source has it, and every viewer shares it. It can only subscribe, it expires, and you can issue a new one and let the old one run out. Per-viewer auth is on the plugin's roadmap and not in it yet.

Conclusion

With the Cloudflare MoQ CDN, your server sends each track to Cloudflare once, no matter how many people watch, so its bandwidth stops being the ceiling. Start on the embedded relay. When the bandwidth graph says it is time, paste the publish token into moqCdnUrl, and your viewers get the same stream, with the same encoder settings, from the Cloudflare relay nearest to them. The setup takes 10 minutes, and the side-by-side test shows you how much delay the CDN adds.

If you want to try it on your own server, Ant Media Server has a free trial, and you can contact the team with questions.

Top comments (0)