P2P (Peer-to-Peer)
架構Direct connection between participants without a central server
What is Peer-to-Peer (P2P)?
Peer-to-Peer (P2P) is a network architecture where devices communicate directly with each other without routing data through a central server. In the context of WebRTC video calling, P2P means that audio and video streams travel directly from one participant's browser to another participant's browser, bypassing intermediary servers once the connection is established.
This is the simplest and most fundamental WebRTC architecture, representing the original vision for browser-to-browser real-time communication. When you make a one-on-one video call in many simple WebRTC applications, you're using P2P architecture.
How P2P Works
In a P2P WebRTC call, the process follows these steps:
- Signaling: Participants exchange connection information through a signaling server (like the room ID, network details, and codec support)
- ICE negotiation: The browsers use STUN servers to discover their public IP addresses and attempt to establish a direct connection
- Direct connection: Once negotiated, media streams flow directly between browsers without passing through any media servers
- Fallback: If a direct connection fails (due to firewalls or restrictive NAT), TURN servers relay the data
Importantly, each device is responsible for its own encoding, decoding, and media processing. No central authority manages the media streams once connections are established.
Key Advantages
Cost-Effectiveness
P2P is the most economical architecture for video calling. Because media doesn't route through servers, you avoid the bandwidth costs and server infrastructure needed to relay or process streams. For one-on-one calls, this translates to virtually zero media server costs.
Low Latency
Direct connections provide the shortest possible path between participants. Without intermediary servers adding processing delays, P2P can achieve the lowest possible latency—often under 100 milliseconds for participants with good connections.
Privacy and Security
P2P offers superior end-to-end encryption because streams don't pass through servers that could decrypt them. Your video and audio travel directly from your device to the recipient's device, encrypted throughout the entire journey. No third party can intercept or access the media content.
Simplicity
From a development perspective, P2P is the easiest WebRTC architecture to implement. You only need a basic signaling server (often just WebSockets) and access to public STUN servers. No complex media server setup or management is required.
Significant Limitations
Limited Scalability
This is P2P's biggest weakness. While it works well for one-on-one calls, it scales poorly beyond 3-4 participants. In a group call, each participant must maintain a separate connection to every other participant. With 4 people, each person sends and receives 3 streams. With 8 people, that becomes 7 streams per person—quickly overwhelming most internet connections and devices.
This "mesh" topology means the number of connections grows exponentially: n(n-1)/2 total connections for n participants. For 10 people, that's 45 separate peer connections to manage.
High Device Resource Usage
Because each device handles all encoding, decoding, and processing for multiple streams, P2P is CPU and memory intensive. Older devices or mobile phones can struggle with the computational load, especially when handling multiple connections simultaneously. Battery drain on mobile devices becomes significant.
Bandwidth Consumption
P2P requires symmetric upload and download bandwidth. If you're in a 4-person call, you're uploading your stream 3 times and downloading 3 streams. Most home internet has asymmetric speeds (higher download than upload), meaning upload bandwidth often becomes the bottleneck.
Inconsistent Quality
Call quality depends entirely on each participant's internet connection and device capabilities. One person with a slow connection or old device degrades their outgoing stream quality for everyone receiving from them. There's no central point to optimize or control quality.
When to Use P2P
P2P architecture makes sense in specific scenarios:
- One-on-one calls: The ideal use case. Simple, fast, private, and cost-effective
- Small groups (2-4 people): Can work well if all participants have good internet connections and modern devices
- Maximum privacy requirements: When end-to-end encryption without server intermediaries is essential
- Low-budget applications: When you need to minimize infrastructure costs
- Prototype/MVP: P2P is the fastest way to build a proof-of-concept video calling application
When NOT to Use P2P
Avoid P2P architecture for:
- Meetings with 5+ participants: Performance degrades rapidly as participant count increases
- Diverse network conditions: When participants have varying connection qualities
- Mobile-heavy applications: Mobile devices struggle with the processing and bandwidth demands
- Recording requirements: No central point to capture the call
- Streaming to many viewers: Broadcasting to dozens or hundreds of viewers is impractical
Hybrid Approaches in 2025
Modern video calling platforms often use adaptive architecture: starting with P2P for one-on-one calls and automatically switching to SFU (Selective Forwarding Unit) when a third participant joins. This hybrid approach provides the benefits of P2P for simple calls while maintaining scalability for larger meetings.
This optimization reduces server costs during the majority of calls (which tend to be one-on-one) while ensuring quality doesn't degrade when more people join.
The Bottom Line
P2P is WebRTC at its simplest and purest: direct browser-to-browser communication with minimal infrastructure. For one-on-one calls, it's unbeatable in terms of simplicity, privacy, and cost. But as soon as you scale beyond 3-4 participants, its limitations become apparent, and more sophisticated architectures like SFU become necessary.
Understanding P2P is essential for anyone working with WebRTC, as it forms the foundation for understanding how browser-based real-time communication works. Even when using SFU or MCU architectures, the underlying peer connections still use the same WebRTC technologies developed for P2P.
References
- Peer-To-Peer (P2P) Architecture - Stream
- WebRTC Architecture Explained: P2P vs SFU vs MCU vs XDN - Red5
- P2P, SFU and MCU - WebRTC Architectures Explained - DigitalSamba
- Peer-to-Peer Video Streaming: Architecture, Advantages & Implementation - VideoSDK
- Why WebRTC Remains Deceptively Complex in 2025 - WebRTC.ventures