Explain the TCP Three-Way Handshake and Its Guarantees
Company: ByteDance
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Walk through the TCP three-way handshake from a client initiating a connection to both endpoints being ready to exchange application data. Explain why each message is needed and distinguish what the handshake establishes from the mechanisms that make data transfer reliable after the connection is established.
### Constraints and Clarifying Questions
- Discuss the ordinary active-client, passive-server opening sequence.
- Use symbolic initial sequence numbers rather than fixed packet values.
- Assume no application data is carried in the handshake packets.
- Clarify whether a claimed property concerns connection establishment, ordered delivery, error detection, or protection against an attacker.
```hint Track both directions
Each endpoint chooses its own initial sequence number. After each handshake message, identify whose sequence number the peer has learned and which control information has been acknowledged.
```
### What a Strong Answer Covers
- The flags, sequence numbers, and acknowledgment numbers in SYN, SYN-ACK, and the final ACK.
- What the client and server learn from the three exchanges.
- Why the server cannot treat its own SYN-ACK transmission as evidence that the client received it.
- The relationship between the handshake and later sequencing, acknowledgments, retransmissions, and checksums.
### Follow-up Questions
- What can happen if the final ACK is lost?
- Why is the acknowledgment of a SYN one greater than its initial sequence number?
- Does a completed handshake prove the peer's application identity or provide cryptographic data integrity?
Overview: Explain TCP's three-way handshake, sequence and acknowledgment numbers, lost final acknowledgments, and the limits of handshake guarantees.