Introduction
There are endless networking protocols. In this post, I want to go over the most common ones you should be aware of. They're all involved in the evolution of HTTP (which I'll tackle in an upcoming post).
What is a packet?
A packet in network communication is a small segment of data sent over a digital network. When data is transmitted over the Internet, it is broken down into smaller, more manageable pieces known as packets. Each packet contains not only a portion of the data you're sending but also important information about the data.
Components of a packet
Header: This part contains control information, such as:
Source and destination IP addresses (tells where the packet is coming from and where it's going).
Protocol type (like TCP or UDP).
Packet number (which helps in reassembling the packets in the correct order).
Payload: This is the actual data that the packet is transporting.
Trailer: This part contains error-checking and other data that ensures the integrity of the packet.
User Datagram Protocol (UDP)
Think of UDP as sending a letter with regular mail. You write your message, put it in an envelope, and send it. However, there's no guarantee it will get to its destination or what shape it will be in when it arrives. There's no confirmation from the receiver, and you don't wait for a response.
Key points of UDP:
Connectionless Protocol: UDP doesn't set up a connection before sending data. In networking, the client (sender) sends data to the server (receiver) without creating a specific communication path.
No Acknowledgment: There's no confirmation from the receiver. In UDP, data packets sent by the client don't get a response from the server. If a packet gets lost, the sender won't know and won't send it again.
Speed Over Reliability: UDP focuses on speed. It's faster than TCP because it doesn't need connection setup, acknowledgment, or error correction. This works well for apps where speed matters more than perfect delivery, such as live video streaming or online gaming.
No Error Correction: If a UDP packet has errors, it gets thrown away. There's no way to fix errors or resend it, unlike TCP.
Non-Sequential Delivery: UDP packets can arrive in any order. There's no rule about the sequence, so the server gets data as it comes, similar to letters that don't always arrive in the order they were sent.
Pros
Speed: UDP is faster because it has minimal error-checking and no acknowledgment mechanism.
Efficiency: It's useful for applications where speed and efficiency are more critical than accuracy.
Cons
No Reliability: There’s no guarantee that the packets will reach their destination.
No Order Guarantee: Packets can arrive out of order.
Use Cases
Live streaming
Online gaming
Voice or Video calls (where minor loss of data is acceptable for the sake of real-time communication)
Transmission Control Protocol (TCP)
TCP is like sending a certified mail. When you send a letter, you get a receipt, and the recipient signs upon delivery. If something goes wrong, the postal service takes steps to correct it.
Key points of TCP:
Connection Establishment: TCP sets up a connection before transferring data. This happens through a process called the 'three-way handshake.' The client and server send syn (synchronize) and ack (acknowledge) messages to make sure both are prepared to communicate.
Acknowledgment of Receipt: Just like getting a notification when your letter is delivered with certified mail, TCP gives acknowledgments for each data packet received. If the sender doesn't get an acknowledgment (like a return receipt), it knows to send the packet again.
Error Correction: If something goes wrong with certified mail (like damage or loss), the postal service tries to fix it. TCP has its own error-checking and resending methods. If a data packet gets lost or damaged, TCP finds the problem and sends the packet again, making sure the data stays accurate.
Ordered Delivery: Certified mail is tracked and delivered in the order it was sent. TCP makes sure that data packets are put back together in the right order, even if they show up out of order. This is really important for keeping complex data like files or web pages accurate.
Reliable and Secure Transmission: Just like certified mail is safer and more reliable than regular mail, TCP is made for trustworthy and secure data transfer. It's used in situations where keeping data accurate is really important, such as sending files, emails, and loading web pages.
Congestion Control: TCP also manages network congestion. It can detect when the network is overloaded with data. It's like recognizing when too many letters are being sent out at the same time, causing delays in the postal system. If it does happen, TCP reduces the speed at which it sends data. This helps avoid unnecessary packet loss.
Pros
Reliability: Ensures data is delivered accurately and in order.
Error Checking: If a packet is lost, TCP retransmits it.
Cons
Slower: This reliability and error-checking come at the cost of speed.
More Overhead: Requires more resources to maintain the connection state and check data integrity.
Use Cases
Email
File transfers
Web browsing
Quick UDP Internet Connections (QUIC)
QUIC is like a fast courier service for important deliveries. When you send a package, it goes out right away, similar to QUIC's quick connection time. The courier carries multiple packages for the same place at once, like QUIC's data stream multiplexing.
If a package gets lost, it's replaced and sent again fast, showing QUIC's quick response to lost data. Also, every package is locked and tracked, similar to QUIC's encryption and security. This service quickly adapts to traffic, making sure the fastest route is used, just like QUIC adjusts to network changes for the best data transfer.
Key points of QUIC:
Rapid Connection Establishment: QUIC speeds up reconnecting to servers you've visited before with its zero-round-trip-time (0-RTT) feature. Unlike TCP, which needs a full handshake for each new connection, QUIC "remembers" past security details. This lets it send encrypted data right away in the first packet when connecting again. This makes connection times much faster than TCP, especially when reconnecting to the same server often. For first-time connections, QUIC does a full handshake like TCP.
Multiplexed Data Streams: QUIC lets many data streams transfer at the same time over one connection. This gets rid of delays caused by blocking in TCP, where one slow stream can stop others.
Improved Packet Loss Handling: When QUIC finds missing packets, it sends them again fast. Unlike TCP, losing packets in one stream doesn't impact other streams, making the overall connection performance more stable.
Built-in Encryption: QUIC has strong encryption for all connections by default. It's like sending each package with a secure, tamper-proof seal, making the data safer and more private.
Stream Independence: In QUIC, each data stream is separate. If there's a problem in one stream, it doesn't affect the others. This is much better than TCP, where a problem in one stream can slow down the whole connection.
Adaptive to Network Conditions: QUIC is made to adjust well to changing network situations, making data flow better for top performance and lowering overall delay.
Pros
Faster Connection Establishment: QUIC offers a faster connection setup compared to TCP, reducing latency and improving performance.
Improved Network Resilience: It handles network changes better than TCP, using connection IDs independent of IP addresses and ports.
Enhanced Security: QUIC encrypts data, headers, and the handshake, providing a more secure method of transport for data.
Lower Latency: It reduces latency and speeds up the initial connection establishment, improving the overall speed of data transfer.
Cons
Limited Adoption: QUIC is not widely adopted by other websites or web servers, and it's not widely supported by cybersecurity tools such as firewalls.
Compatibility Challenges: It faces challenges from firewalls, NATs, or proxies that may block or interfere with UDP traffic.
Use Cases
Web Browsing: QUIC supports built-in TLS and establishes connections rapidly, providing significant performance benefits, such as faster download times for secured websites.
Video Streaming: It supports features expected to improve Quality of Experience (QoE) for video streaming, such as mitigating "head of the line blocking".
Mobile Apps: It is used by mobile apps that rely on a stable, fast connection, benefiting from reduced packet loss and improved efficiency.