Lesson 02: Reliability

Sequence Numbers & RTO

IP (Internet Protocol) guarantees absolutely nothing. Packets can be duplicated, delayed, delivered out of order, or simply dropped entirely. TCP's primary job is to create the illusion of a perfect, orderly byte stream on top of this chaos.

To do this, TCP assigns a Sequence Number to every single byte of data it sends. If you send a 100-byte packet starting at Sequence Number 1000, the packet covers bytes 1000 to 1099.

Cumulative Acknowledgments

When the receiver gets that packet, it doesn't say "I got packet 1". Instead, it sends an ACK (Acknowledgment) with the number 1100. This means: "I have successfully received all bytes up to 1099. I am expecting byte 1100 next."

Because ACKs are cumulative, if a sender transmits 3 packets and only the ACK for the 3rd one arrives, the sender knows all 3 packets arrived safely. But what happens if a packet is lost?

Retransmission Simulator

Click "Send Data" to transmit 100 bytes. Try clicking "Drop Next Packet". Notice how the sender keeps a copy of the unacknowledged data in memory and starts a Retransmission Timeout (RTO) timer. When the timer expires without an ACK, it resends.

SENDER Unacked Queue 0 bytes RTO TIMER RECEIVER Expecting Seq: 1000
Ready.

The time the sender waits before retransmitting (the RTO) is dynamically calculated. If the network is generally fast, the RTO is short. If the network is slow, the RTO is long. If a packet is lost, the sender retransmits and doubles the RTO for the next try. This exponential backoff prevents the sender from spamming an already overwhelmed network.

The Cost of Loss: Packet loss is devastating for latency. If the round-trip time (RTT) is 50ms, a dropped packet might mean the sender waits an entire RTO (e.g., 200ms) doing absolutely nothing before it retransmits. This is why a 1% packet loss on a connection makes an app feel sluggish, even if you have gigabit bandwidth.

Out-of-Order Delivery

If you send packet 1 (bytes 0-99) and packet 2 (bytes 100-199), and packet 1 is delayed while packet 2 arrives first, what does the receiver do?

The receiver buffers packet 2 in memory but cannot hand it to the application yet, because the application expects a perfect stream. It also replies with an ACK for byte 0: because that's still the next byte it expects in contiguous order. Once packet 1 finally arrives, the receiver can immediately ACK 200, acknowledging both packets at once.

Check yourself

1. What happens if a sender drops a packet due to network congestion?

TCP uses exponential backoff. If a packet is lost, it assumes the network is congested and doubles the wait time before trying again to avoid adding fuel to the fire.

2. A receiver has successfully received bytes 0-99 and 200-299. It receives a packet containing bytes 300-399. What does it send back?

TCP ACKs are strictly cumulative. The receiver still has not received bytes 100-199, so it must continue ACKing 100 to tell the sender "the next contiguous byte I need is 100".