Interview Q&A / Computer Networks

INTERVIEW Q&A · 55 QUESTIONS

Computer Networks interview questions

What happens when you open a website, TCP vs UDP, DNS and HTTP.

  1. What is the difference between TCP and UDP?

    TCP is connection-based and reliable, with ordering, retransmission and flow control, so it suits web pages, email and file transfer. UDP just sends datagrams with no guarantees, so it is faster and lighter and suits video calls, games, DNS and live streaming.

    BeginnerIn-depth3 min read
  2. What do the TCP flags SYN, ACK, FIN and RST mean?

    SYN starts a connection and syncs sequence numbers, ACK acknowledges received data, FIN politely closes one direction, and RST aborts the connection immediately. PSH asks the receiver to hand data to the app without waiting.

    BeginnerQuick answer1 min read
  3. What is HTTP keep-alive, and why does it speed up page loads?

    Keep-alive reuses one TCP connection for several HTTP requests instead of opening a new one each time. This saves the handshake round trips (and the TLS handshake for HTTPS) for every file after the first. It is the default in HTTP/1.1.

    BeginnerQuick answer1 min read
  4. When would you choose UDP over TCP? Give real examples.

    Choose UDP when speed and low delay matter more than perfect delivery, or when the app wants its own control: live video calls, online games, DNS lookups, and streaming. Old data is useless in real time, so waiting for a retransmission is worse than skipping it.

    BeginnerQuick answer1 min read
  5. Why does TCP use a three-way handshake, and why not two?

    The handshake lets both sides agree on starting sequence numbers and confirm that each can send and receive. Two steps would prove only that the server can hear the client, so a delayed old SYN could make the server open a connection nobody wants.

    BeginnerQuick answer1 min read
  6. How do TCP slow start and congestion avoidance work? Trace cwnd over time.

    Slow start doubles the congestion window every round trip from a small start until it reaches a threshold (ssthresh). After that, congestion avoidance grows it by about one segment per round trip. On a timeout, ssthresh becomes half the window and cwnd restarts small.

    IntermediateQuick answer1 min read
  7. How does TCP detect and recover from a lost packet?

    The sender retransmits when its timer expires without an ACK, or sooner if it receives three duplicate ACKs, which signal that later segments arrived but one is missing. That second path is called fast retransmit.

    IntermediateQuick answer1 min read
  8. How does the TCP sliding window work? Give a small example.

    The receiver advertises how many bytes it can accept. The sender may keep that many bytes in flight without waiting for ACKs, and as each ACK arrives the window slides forward so new data can be sent. This keeps the link busy instead of stop-and-wait.

    IntermediateQuick answer1 min read
  9. How is a TCP connection closed, and what is the TIME_WAIT state?

    Each side closes its own direction with FIN and the other side ACKs it, so teardown takes four segments. The side that closes first then waits in TIME_WAIT, about twice the maximum segment lifetime (60 seconds on Linux), to catch late packets and to resend the last ACK if lost.

    IntermediateQuick answer1 min read
  10. What is a socket, and how can one server handle thousands of clients on port 443?

    A socket is one endpoint of a connection: an IP address plus a port plus a protocol. A TCP connection is identified by the four-tuple of source IP, source port, destination IP and destination port, so many clients can share the server's port 443 because each tuple is unique.

    IntermediateQuick answer1 min read
  11. What is the difference between TCP flow control and congestion control?

    Flow control stops a fast sender from overwhelming a slow receiver, using the receiver's advertised window. Congestion control stops senders from overwhelming the network in between, using a congestion window the sender maintains itself. The sender obeys the smaller of the two.

    IntermediateQuick answer1 min read
  12. Why does DNS mostly use UDP, and when does it switch to TCP?

    A DNS lookup is one small question and one small answer, so UDP avoids the cost of a handshake. DNS falls back to TCP when the answer is too large for a UDP response (truncated flag set), for zone transfers, and for DNS over TLS.

    IntermediateQuick answer1 min read