Three-Way:
Client → SYN → Server
Client ← SYN-ACK ← Server
Client → ACK → Server
Four-Way Termination:
Client → FIN → Server
Client ← ACK ← Server
Client ← FIN ← Server
Client → ACK → Server
L4 (Transport): Routes by IP+port, fast
L7 (Application): Routes by HTTP headers/URL, flexible
Algorithms:
Round Robin: Rotate through servers
Least Connections: Server with fewest connections
IP Hash: Same client → same server (sticky)
Weighted: More powerful servers get more traffic
Full-duplex, persistent connection over TCP
Upgrade from HTTP via handshake
Use: Real-time chat, gaming, live updates, notifications
vs HTTP:
HTTP: Request → Response → Close
WebSocket: Bidirectional, persistent
Cookie: Client-side, sent with requests, size limit
Session: Server-side, identified by session ID
Token (JWT): Self-contained, stateless, includes claims