TCP vs UDP: what is the difference?
TCP and UDP are transport-layer protocols with opposite priorities. TCP is connection-oriented and reliable: it establishes a connection (the three-way handshake), guarantees that bytes arrive in order, retransmits lost packets, and applies flow and congestion control. That reliability adds latency and overhead.
UDP is connectionless and best-effort: it just sends datagrams with no handshake, no ordering guarantee, and no retransmission. That makes it lightweight and fast, but the application must tolerate or handle loss itself.
Use TCP when correctness matters more than latency — web pages (HTTP), email, file transfer. Use UDP when speed and low latency beat perfect delivery, and occasional loss is acceptable — live video and voice, gaming, DNS lookups. A strong interview answer pairs the technical contrast (reliable/ordered vs fast/best-effort) with concrete examples of each.