The world’s leading publication for data science, AI, and ML professionals.

All You Should Know About Computer Network in Technical Interviews

A complete guide to handle common computer network questions in technical interviews

Photo by Su San Lee on Unsplash
Photo by Su San Lee on Unsplash

"Are you ready for the Interview now?"

"Yes, of course. Please start."

"Great. Could you please talk about your understanding of computer networks? Maybe we can start with what TCP is and how it works. "

"Umm…Umm…Umm……."

"Okay, thanks for your time today. Please wait for our further notice in the next few days."

Does this seem similar to you?

Don’t give up. You definitely can do it better.

Here are some common computer network problems you would face in technical interviews. Most of them are related to the application, transport, and network layers. You can follow this guide to learn computer networks from scratch and clearly explain them to your interviewer.


1. What is the architecture of a computer network?

In general, computer network concepts often be divided into 5 main layers. This is a combination of the OSI (Open System Interconnection) model and TCP/IP model, which have 7 layers and 4 layers respectively.

Different Models of Computer Networks (Image by Author)
Different Models of Computer Networks (Image by Author)

2. What are the functions of each layer?

The following introduction will be based on the OSI network model:

  1. Application: The application layer’s task is to specify the communication protocols or interfaces between application processes run by the host. There are some general protocols in the application layer, e.g., HTTP (Hypertext Transfer Protocol), DNS (Domain Name System), and SMTP.
  2. Presentation: This layer is mainly responsible for translating data from the application layer into the required format (e.g., ASCII). Some work such as data encryption/decryption and compression is done here.
  3. Session: This layer is responsible to establish and maintain a connection or session between two processes. It also allows processes to add checkpoints for synchronization.
  4. Transport: It provides the end-to-end data (segments) transfer service between applications over networks. The best-known protocols of the transport layer are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).
  5. Network: The network layer is responsible for the packet (data chunks) routing. To be specific, the network layer chooses the suitable routes for transmission and sends and receives IP (Internet Protocol) packets from other networks.
  6. Data link: This layer encapsulates IP packets from the network layer into frames and sends them over link nodes. Frame transmission depends on the MAC (Message Access Control) address. The receiver’s MAC address could be retrieved by sending ARP (Address Resolution Protocol) requests to see if any node has the required IP address.
  7. Physical: It is responsible for bit transmission between nodes, which is the physical connection (over physical data link), and eliminates the difference between devices as much as possible.

3. What is TCP & UDP in the transport layer? What are their differences?

TCP (Transmission Control Protocol) is a connection-oriented service, which means it builds connection before transferring data and closes the connection after the transmission.

The reliability of TCP reflects on establishing a connection by a three-way handshake, and some mechanisms like error detection, flow control, congestion control, and retransmission. Those features will cost a lot of overhead and occupy the resources of processors.

TCP is often used in the file transmission, sending and receiving of mail, and remote login.

UDP (User Datagram Protocol) does not need to build a connection before the data transmission, which means that the remote host is not required to acknowledge after receiving UDP segments.

Although UDP cannot provide reliable transmission, it is the most effective service under certain situations (instant messaging in general), e.g., real-time audio and video streaming.

TCP v.s. UDP (Image by Author)
TCP v.s. UDP (Image by Author)

4. How does TCP build and terminate the connection?

We’ll first look at how TCP build connection in the Client/Server model, which is generally called a three-way handshake:

  1. Client: It sends a SYN segment, which requests the server to synchronize its sequence number with the client’s sequence number.
  2. Server: After receiving the packet from the client, the server will return SYN and ACK segments, which informs the client side that the packet had been received and asks it to provide the expected sequence number for the acknowledgment.
  3. Client: It sends back a packet with an ACK segment, which informs the server that the returned packet had been correctly received.
TCP Connection Establishment (Image by Author)
TCP Connection Establishment (Image by Author)

SYN segments confirm that the route from a sender to a receiver has no issue, but the route from a receiver to a sender should be confirmed by ACK segments.

Next, we’re going to discuss how TCP terminates the connection in a Client/Server model, which is a four-way handshake process:

  1. Client: After deciding to close the connection, the client will send a FIN segment to the server. Then the client will enter the FIN_WAIT_1 state waiting for the acknowledgment from the server.
  2. Server: It sends back an ACK segment once the FIN segment from the client is received.
  3. Client: It enters the FIN_WAIT_2 state after receiving the ACK segment from the server, which is waiting for a FIN segment sent from the other side.
  4. Server: It also closes the connection with the client and sends a FIN segment after it sent the ACK segment.
  5. Client: Once the ACK segment from the server is received, the client sends back the final ACK segment for acknowledgment. After, the client will enter the TIME_WAIT state, which the client formally closes after a while in case the final ACK segment is not received by the other side.

5. What is ARQ (Automatic Repeat Request)?

ARQ is an error-control method for data transmission in the transport layer and data link layer.

Acknowledgments and timeouts are used to ensure reliable data transmission. If a receiver doesn’t get the acknowledgment within a given time, it will resent the same packet until an acknowledgment has been returned or exceeding the pre-defined times of retransmission.

There are two types of ARQ, including:

  • Stop-and-wait ARQ: The basic idea of Stop-and-wait ARQ is the sender will stop data transmission after each time sending a packet. The transmission will be regarded as a failure if getting no acknowledgment from the receiver after a given time. This means the data should be retransmitted until receiving the acknowledgment. If the receiver receives a duplicated packet, it should abandon this packet and send back an acknowledgment at the same time.
  • Go-Back-N ARQ: The sender maintains a sliding window, which packets within this window can be sent continuously and there is no need to wait for acknowledgments. The receiver generally receives only in-order packets and sends back cumulative ACK after the last packet arrived.

6. How does TCP achieve flow control?

The purpose of flow control is to control the speed of packet sending, which ensures the receiver can receive it in time.

TCP can achieve flow control by sliding windows. The sliding window size at the sender side can be controlled by ACK segments returned by the receiver, which can also affect the sending speed.

7. How does TCP achieve congestion control?

Network congestion happens when the requests for a network resource exceeds the amount of data it can handle.

Congestion control is to prevent excessive data from injected into the network so that the network links or nodes will not be overloaded.

TCP congestion control adopts various strategies, which are:

  1. Slow start: Rather than ingesting a large amount of data into the network, TCP detects the resource allowance by first sending a small piece of data and gradually increase the congestion window (cwnd) size exponentially after each RTT (Round Trip Time).
  2. Congestion avoidance: After the congestion window (cwnd) size reaching the threshold, it starts increasing additively to avoid network congestion.
  3. Congestion detection: This happens when congestion occurs, the congestion window size will multiplicatively decrease. The congestion is assumed to happen when the packet retransmission is needed.
  4. Fast retransmit and recovery (FRR): It is a congestion control algorithm that could fast recover lost packets. Without FRR, TCP will pause the transmission by a timer. During the pause, no new packets will be transmitted. With FRR, if the receiver receives a segment, it will return a duplicate ACK segment immediately. The sender will assume the segment lost after receiving three duplicate ACK segments. FRR reduces the delay of retransmission.

8. What is the process from entering the URL to displaying the web page?

This process can be divided into a few steps:

  1. DNS resolution.
  2. Build a TCP connection.
  3. Send HTTP request.
  4. The server handles the request and returns an HTTP response.
  5. The browser renders the web page.
  6. Close connection.
The Process of Accessing URL and Protocols Used (Image by Author)
The Process of Accessing URL and Protocols Used (Image by Author)

8. How does HTTP save user status?

HTTP is a "stateless" protocol, which means it doesn’t save the connection status between requests and responses itself.

So how do we save user status?

Sessions are managed to solve this problem. The main feature of sessions is to record user status from the server-side.

For instance, while you putting some products into your Amazon shopping cart, and thinking of buying them later. The system actually cannot know who is saving those items via HTTP since it is stateless. So the server will create and keep a specific session for you, which enables tracking your shopping information.

9. What are cookies in a computer network? What is the difference between cookies and sessions?

Both cookies and sessions can track and store user identity, but they’re often be used in different scenarios.

Cookies are generally used to store user information. For example, after we log into a website, next time we do not need to log in again since our security details have been stored as a token in a cookie. The system just has to find the user based on token value.

Sessions record user status via server. The typical scenario of using sessions is online shopping carts. As HTTP is stateless, the server will track user status by marking them with a session.

Cookie data are stored on the client-side (browser), whereas session data are stored on the server-side. This implies that sessions have a higher security level comparing to cookies.

10. What is the difference between HTTP and HTTPS?

HTTP runs beyond the TCP and transfers the content with plaintext. Both client and server sides cannot verify each other’s identity.

HTTPS (Hypertext Transfer Protocol Secure) is the HTTP that runs beyond SSL/TLS, which SSL/TLS running beyond the TCP. All the content transferred is encrypted.

Hence, the security of HTTPS is higher than HTTP, but HTTPS requires more resources than HTTP.

References

  1. Layers of OSI Model
  2. TCP/IP Model
  3. Transmission Control Protocol – Wikipedia
  4. TCP Connection Establishment
  5. TCP Connection Termination
  6. Stop-and-wait ARQ
  7. Go-Back-N ARQ
  8. How the TCP/IP Protocols Handle Data Communications
  9. Difference between Stop and Wait, GoBackN and Selective Repeat
  10. TCP congestion control

To be clear, there is still a lot of knowledge related to computer networks. Since common technical interviews, especially the junior software engineer interview, often focus on the upper half of network layers, those problems we’ve seen are only a small part of this field.

Hope you find it useful and good luck with your next interview!


Related Articles