Skip to main content
This guide explains the practical differences between TCP and UDP using a WhatsApp-style backend as an example: text messages, voice/video calls, and how apps pick the appropriate transport for each use case.

Text messaging: why TCP fits

When you send a text like “I’m running late, be there in ten”, the receiver must get exactly what you typed — no missing words, no reordering. TCP provides:
  • Reliable delivery (retransmits lost data),
  • In-order delivery (reassembles packets using sequence numbers),
  • Flow and congestion control (keeps the network stable).
These features make TCP ideal for messaging and other data that must arrive intact and in order.
The image explains how a text message should be delivered correctly by TCP, showing a message saying "I'm running late, be there in ten," emphasizing delivery without errors like "Be ten in there."

Connection setup: TCP three-way handshake

Before application data flows, TCP performs a three-way handshake:
  1. Client sends SYN (request to open connection).
  2. Server replies with SYN-ACK (acknowledges request).
  3. Client sends ACK (completes handshake).
Only after this exchange can the devices start reliable data transfer.
The image illustrates the TCP 3-way handshake process between a phone and a WhatsApp server, showing the exchange of SYN, SYN-ACK, and ACK packets.

Packetization, ordering, and retransmission

Once the connection is established, TCP breaks data into segments, assigns sequence numbers, and handles:
  • Missing packets: the receiver detects gaps and triggers retransmission.
  • Out-of-order arrivals: TCP reorders packets before handing data to the application.
This guarantees the application sees a continuous, ordered byte stream.
The image illustrates a network communication scenario where a packet labeled "#2" goes missing between a phone and a server.

Real-time audio/video: why UDP is usually preferred

Voice and video calls stream many small packets continuously. For real-time media, timeliness matters more than recovering every lost packet. Using TCP introduces two key problems for live streams:
  • Head-of-line blocking: later packets wait for retransmissions of earlier lost packets, causing pauses.
  • TCP congestion response: loss causes reduced send rates, increasing latency and making audio/video choppy.
Because a brief packet loss may be less harmful than a stalled stream, real-time applications commonly use UDP for media transport.
The image depicts a concept related to voice calls, indicating a continuous audio stream with packet representation, and notes that TCP is not used.

What UDP provides — and what the application layer adds

UDP itself is minimal: no handshake, no guaranteed delivery, no automatic retransmission, and no enforced ordering. Real-time apps build reliability and timing handling in the application layer, typically using protocols such as RTP/SRTP. Application-layer techniques include:
  • Sequence numbers and timestamps (detect lost/late packets and reorder),
  • Jitter buffers (smooth variable arrival times),
  • Selective retransmission or forward error correction (for non-real-time-critical parts),
  • Dropping packets that arrive too late to be useful.
SRTP (Secure RTP) can add confidentiality and integrity for RTP streams carried over UDP.
The image describes UDP (User Datagram Protocol) as having no guarantees, no handshake, no retries, and no ordering, with SRTP (Secure Real-time Transport Protocol) adding sequence numbers and timestamps to audio packets.

Use both protocols where appropriate

Many apps keep both connection types simultaneously:
  • Media (real-time voice/video): UDP + RTP/SRTP, optimized for low latency.
  • Text, file transfer, or control messages: TCP or TLS over TCP (HTTP/2) for reliability and ordering.
Choose the transport based on whether timeliness or guaranteed delivery is the priority.

Security is orthogonal to TCP vs UDP

Neither transport encrypts payloads by default. Security (encryption, authentication, integrity) must be added at a higher layer:
  • Use TLS to secure TCP streams.
  • Use SRTP to secure RTP over UDP.
  • Use end-to-end application protocols (e.g., Signal Protocol) for message-level encryption.
Neither TCP nor UDP provides encryption by default. Use TLS, SRTP, or an application-level protocol (e.g., Signal Protocol) to secure transported data.
The image shows a comparison of different security protocols: Signal Protocol with end-to-end encryption, WhatsApp Encryption involving phone and server communications, and TCP/UDP with cleartext transport and no security.

Quick comparison

Summary

  • Use TCP when you need reliable, ordered delivery (e.g., text, files, transactional data).
  • Use UDP when low latency and timeliness trump perfect delivery (e.g., real-time voice/video), and rely on RTP/SRTP or application logic for sequencing, jitter management, and security.
  • Encryption and authentication are implemented at higher layers — choose TLS, SRTP, or application-level end-to-end protocols as required.

Watch Video