Each test is 5 questions with varying difficulty.
AI Prep covers AI Agents, Generative AI, ML Fundamentals, NLP & LLMs and a lot more, with adaptive tests and daily challenges. Fully offline on Android. Free to try, one-time unlock for lifetime access.
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) form the bedrock of transport layer communication in modern distributed systems. As we move into 2026, understanding these protocols is critical for engineers building high-performance AI inference services, real-time streaming platforms, and robust microservice architectures. TCP provides a reliable, ordered, and error-checked byte stream, while UDP offers a lightweight, connectionless datagram service that prioritizes speed over delivery guarantees. Interviewers ask about these protocols to test a candidate's ability to make architectural tradeoffs: choosing between the overhead of reliability and the necessity of low-latency delivery. Junior engineers are expected to explain the basic differences in headers and flow control, while senior engineers must demonstrate deep knowledge of congestion control algorithms (like BBR or CUBIC), head-of-line blocking, and how these protocols interact with modern application-layer stacks like HTTP/3 (QUIC) and gRPC.
The choice between TCP and UDP is a fundamental architectural decision that dictates the performance characteristics of an entire system. In 2026, with the rise of massive-scale AI inference and real-time collaborative environments, the cost of TCP's reliability mechanismsβspecifically retransmission delays and head-of-line blockingβcan be prohibitive. For example, a real-time voice agent or a high-frequency trading platform cannot afford the latency spikes inherent in TCP's congestion window recovery. Conversely, for critical data transfers like database replication or financial transactions, the reliability and ordering guarantees of TCP are non-negotiable. This topic is a high-signal interview question because it reveals whether a candidate understands the 'cost' of abstractions. A strong candidate will not just recite the differences; they will analyze the impact of packet loss on application state, discuss how modern protocols like QUIC attempt to bridge the gap by implementing reliability in user-space, and explain how to tune kernel-level parameters like TCP_NODELAY or socket buffer sizes to optimize performance for specific traffic patterns.
TCP manages data through a stateful socket interface that interacts with the kernel's network stack to ensure reliability, while UDP acts as a thin wrapper over IP, delegating all reliability and ordering logic to the application layer.
Data flows from the application through the socket into the kernel buffer, where TCP segments it, assigns sequence numbers, and manages flow control, while UDP passes raw datagrams directly to the IP layer.
Application Layer
β
[Socket API (send/recv)]
β
[TCP State Machine] [UDP Wrapper]
β β β
[Send Buffer] [ACKs] [IP Layer]
β β β
[Congestion Control] β-----β
β
[Network Interface]
Implementing custom sequence numbers and ACKs on top of raw UDP sockets for specific low-latency requirements.
Trade-offs: High engineering complexity vs. complete control over retransmission logic.
Configuring SO_KEEPALIVE and idle timeouts to detect dead peers in long-lived connections.
Trade-offs: Reduces stale connection overhead vs. increased control traffic.
Setting TCP_NODELAY to disable Nagle's algorithm, forcing immediate packet transmission for small messages.
Trade-offs: Reduces latency for small packets vs. increased header overhead per byte.
| Reliability | TCP handles retransmissions via kernel timers; UDP requires application-level ACK/NACK strategies. |
| Scalability | TCP state management on the server can limit concurrent connections; UDP is stateless and scales better for massive connection counts. |
| Performance | TCP is limited by HOL blocking and congestion control; UDP offers lower latency but requires more application logic. |
| Cost | TCP consumes more CPU and memory per connection; UDP is cheaper per-packet but requires more developer time. |
| Security | TCP is susceptible to SYN flood attacks; UDP is susceptible to amplification/reflection DDoS attacks. |
| Monitoring | Track retransmission rates (TCP), packet loss (UDP), and round-trip time (RTT) metrics. |
Not necessarily. While UDP lacks the overhead of a handshake and retransmissions, it also lacks built-in flow and congestion control. If you implement these features in your application to ensure reliability, you may end up with a custom protocol that is less efficient than the highly optimized kernel-level TCP stack.
It is a performance issue where a lost packet prevents the delivery of all subsequent packets in the stream, even if they have arrived at the destination. Because TCP must deliver data in order, the entire stream stalls until the missing segment is retransmitted and received.
The three-way handshake (SYN, SYN-ACK, ACK) ensures that both the client and server are ready to communicate and have agreed upon initial sequence numbers. This synchronization is necessary to establish the reliable, ordered stream that TCP guarantees.
Yes, but you must implement your own reliability layer (e.g., sequence numbers, ACKs, retransmissions) at the application level. Protocols like TFTP or specialized high-speed transfer tools do this, but for most general-purpose file transfers, TCP is preferred due to its robust, battle-tested implementation.
Flow control (TCP windowing) prevents a fast sender from overwhelming a slow receiver. Congestion control (e.g., CUBIC, BBR) prevents a sender from overwhelming the network infrastructure (routers/switches) between the endpoints, which could lead to packet loss and network collapse.
TCP provides the reliability and ordering required for web content. HTTP/1.1 and HTTP/2 rely on TCP to ensure that data chunks are reassembled correctly. However, HTTP/3 moves to QUIC (over UDP) to solve the head-of-line blocking issues inherent in TCP.
Disable Nagle's algorithm by setting the TCP_NODELAY socket option. This forces the kernel to send packets immediately rather than buffering them to fill a full MTU, significantly reducing latency for small request/response messages.
UDP is neither secure nor insecure by itself. Because it is connectionless, it is more susceptible to IP spoofing and amplification DDoS attacks. Security for UDP-based traffic must be implemented at the application layer, often using protocols like DTLS (Datagram Transport Layer Security).
The theoretical maximum is 65,535 bytes, but in practice, you should keep UDP payloads below the path MTU (typically 1500 bytes) to avoid IP fragmentation, which can lead to high packet loss rates and performance degradation.
If no data is sent, the connection remains open but dormant. To detect if the peer has crashed or the network path is broken, you can enable TCP Keep-Alive, which sends periodic empty probes to verify the connection is still active.
AI Prep covers AI Agents, Generative AI, ML Fundamentals, NLP & LLMs and a lot more, with adaptive tests and daily challenges. Fully offline on Android. Free to try, one-time unlock for lifetime access.