Real-Time YouTube Sync Engine (Leader–Follower Model)
Watch Together now runs on a structured Leader–Follower architecture:
- One user becomes the Leader (controls playback)
- All others act as Followers
- Every play, pause, seek, and quality change is instantly broadcast
- Followers automatically reconcile their playback state
This removes inconsistent playback behavior and eliminates manual re-syncing.
Drift Correction (< 0.5s Max)
Followers continuously compare their playback time with the Leader.
- If the drift exceeds 0.5 seconds, an automatic
seekTo()correction is triggered. - If the drift is within tolerance, no correction is applied to avoid jitter.
Result:
- Smooth playback
- No micro stutters
- No visible desync
Intelligent Buffering Coordination
If any participant starts buffering:
- A
bufferingevent is broadcast - All peers pause together
- Playback resumes only when everyone reports
ready
No more:
- “I’m ahead of you”
- “Wait, pause it”
- Manual syncing
Dual Transport Sync System
Sync messages now prefer:
- WebRTC DataChannel (~20ms latency) for near-instant P2P sync
- Automatic fallback to Socket.IO (~150ms latency) when P2P is unavailable
This ensures:
- Low latency in optimal conditions
- Reliability on restricted or slow networks
- No additional heavy server load when P2P is active
Technical Improvements
- Timestamp-based state reconciliation
- Optimized sync payload structure
- Reduced redundant re-renders during sync events
- Cleaner teardown of Watch Together sessions
- Improved debugging logs for drift and buffering
Why This Matters
- Max drift capped at under 0.5 seconds
- Zero desync during buffering
- Stable performance across mixed network conditions
- Production-ready sync logic
v2.5.0 lays the foundation for future shared media features inside PieVideo.
What's Changed
- feat: v1.5 sync engine architecture, README update, production server… by @souvik082003 in #5
Full Changelog: v1.1.0...v2.5.0