Configure WebRTC RTCDataChannel Reliability

This article explains how to explicitly configure the WebRTC RTCDataChannel for either reliable or unreliable packet delivery. You will learn about the configuration parameters used during channel creation, including how to mimic TCP-like reliability or UDP-like speed and low latency depending on your application’s specific requirements.

Yes, the WebRTC RTCDataChannel can be explicitly configured for either reliable or unreliable packet delivery. By default, a data channel acts like a traditional TCP connection—guaranteeing that data packets arrive in order and without loss. However, you can customize this behavior during the channel’s creation to match UDP-like behavior for real-time applications like gaming, VoIP, or live streaming.

How to Configure Reliability

Configuration is handled via the options object (of type RTCDataChannelInit) passed as the second argument to the RTCPeerConnection.createDataChannel() method.

Here is an example of how to create both types of channels:

const peerConnection = new RTCPeerConnection();

// 1. Reliable and Ordered (Default TCP-like behavior)
const reliableChannel = peerConnection.createDataChannel("reliableData");

// 2. Unreliable and Unordered (UDP-like behavior)
const unreliableChannel = peerConnection.createDataChannel("unreliableData", {
  ordered: false,
  maxRetransmits: 0 // No retransmissions allowed
});

Key Configuration Parameters

To customize the reliability and ordering of packet delivery, you use three primary properties in the configuration object:

Configuration Rules and Limitations

When setting up custom reliability, keep the following rules in mind:

  1. Mutual Exclusion: You cannot specify both maxPacketLifeTime and maxRetransmits in the same configuration object. Attempting to set both will result in a syntax error or a failed channel creation.
  2. Partially Reliable: If you set ordered to true but limit maxRetransmits or maxPacketLifeTime, the channel becomes partially reliable. Packets will be delivered in order, but some packets may be lost if they exceed the defined retransmission limits.
  3. Fully Unreliable: To achieve a true UDP-like experience, set ordered to false and set either maxRetransmits: 0 or a very low maxPacketLifeTime. This ensures data is sent with minimum overhead, never retransmitted, and processed immediately upon arrival.