Computer Networks Interview Questions · Question 18

How does TCP provide reliable and ordered data delivery?

Interview preparation resource from Gate Smashers.

Interview-ready answer

TCP provides reliable, ordered delivery by treating data as a byte stream with sequence numbers. The receiver acknowledges received bytes, detects gaps or corrupted segments, and the sender retransmits data that is not acknowledged. If data arrives out of order, the receiver holds it until missing earlier bytes arrive, then delivers only the contiguous byte stream to the application.

Computer Networks Interview Questions diagram explaining How does TCP provide reliable and ordered data delivery
Understand it clearly

Sequence numbers and ordered byte streams

TCP assigns sequence numbers to bytes in the stream. These numbers let the receiver determine the position of each received byte, identify missing ranges, and recognize duplicate data.

The receiving TCP implementation delivers data to the application only in sequence order. Data that arrives beyond a gap may be buffered until the missing bytes are received.

Acknowledgments and retransmission

The receiver sends acknowledgments indicating the next byte it expects, which cumulatively confirms receipt of all preceding bytes. When supported by both endpoints, Selective Acknowledgment (SACK) can additionally report received noncontiguous ranges.

TCP does not receive an explicit loss notification from IP. Instead, the sender infers loss when an acknowledgment is not received before a retransmission timeout or from patterns of duplicate acknowledgments, then retransmits the missing or unacknowledged data.

Corruption and duplicate handling

Each TCP segment includes a checksum. A segment that fails checksum validation is discarded and is not delivered to the application; the absence of an acknowledgment can cause the sender to retransmit it.

Sequence numbers also allow the receiver to recognize retransmitted or duplicated data and avoid delivering the same bytes more than once to the application.

Flow and congestion control

Flow control uses the receiver-advertised window to limit the amount of unacknowledged data the sender may have in flight, helping prevent the receiver's buffer from being overrun.

Congestion control adjusts the sender's transmission behavior in response to perceived network congestion. It supports efficient network use, but the core reliability mechanisms are acknowledgments, checksums, sequencing, buffering, and retransmission.