Chapter 04 · Cloudflare Deploy
Subchapter 4.177
references/realtime-sfu/README.mdMarkdown3 KBView on GitHub
Expert guidance for building real-time audio/video/data applications using Cloudflare Realtime SFU (Selective Forwarding Unit).
| Task | Files | ~Tokens |
|---|---|---|
| New project | README → configuration | ~1200 |
| Implement publish/subscribe | README → api | ~1600 |
| Add PartyTracks | patterns (PartyTracks section) | ~800 |
| Build presence system | patterns (DO section) | ~800 |
| Debug connection issues | gotchas | ~700 |
| Scale to millions | patterns (Cascading section) | ~600 |
| Add simulcast | patterns (Advanced section) | ~500 |
| Configure TURN | configuration (TURN section) | ~400 |
Cloudflare Realtime SFU: WebRTC infrastructure on global network (310+ cities). Anycast routing, no regional constraints, pub/sub model.
Core concepts:
Mental model: Your client establishes one WebRTC session, publishes tracks (audio/video), shares track IDs via your backend, others subscribe to your tracks using track IDs + your session ID.
| Approach | When to Use | Complexity |
|---|---|---|
| PartyTracks | Production apps with device switching, React | Low - Observable-based, handles reconnections |
| Raw API | Custom requirements, non-browser, learning | Medium - Full control, manual WebRTC lifecycle |
| RealtimeKit | End-to-end SDK with UI components | Lowest - Managed state, React hooks |
Recommendation: Start with PartyTracks for most production applications. See patterns.md for PartyTracks examples.
Use SFU directly when you need custom signaling or non-React framework. Use RealtimeKit for faster development with React.
Get CALLS_APP_ID and CALLS_APP_SECRET from dashboard, then see configuration.md for deployment.