Backend Engineering

Backend Accepting Connections

brian | Published: March 2, 2024, 11:41 a.m. | Updated: May 25, 2025, 8:22 p.m.

Profile Picture

Connection Establishment

1. The server listens on IP addresses and ports and specifies what exactly is it that we're listening to. For example lets say we are listening on port 8080, and we don't specify what we're listening to, then we are now listening to all the network interfaces (0.0.0.0).

 

2.  Let's say the client wants to connect, in turn the kernel does the 3 way handshake, and then the connection is established. Here is how that is done 

1. When we are listening to address and port, the kernel creates a socket & 2 queues "SYN and Accept". Aswell as the 'Send and Receive" buffers(We will talk about that in the next article) "article"

2. The client sends a SYN

3 .The kernel adds that SYN to the SYN queue, and replies with a SYN ACK 

 4. Client replies with another ACK .... 

 

5.   kernel removes the SYN from SYN queue, and adds full connection to "Accept Que". 

 

6. The kernel then notifies the Backend, and the backend will accept the connection from the kernel using the (accept() method), and move the connection from the kernel to it's own process

 

7.The backend process then proceeds to handle the connection, performing tasks such as request processing, data transmission, and response generation.

 

 

 

Problems that can arrise when accepting connections

1. backend is not accepting fast enough, leaading to loading web pages

2. Clients who dont ACK.  

 

 

Source to article below

Flood DDOS

 

3. Small backlog: it is basically a queue for incoming connection requests, and if you have more traffic than you can handle, this can cause the page to load slower than normal

 

Things To Note

2. Listening on IP Addresses and Ports: When a server listens on an IP address and port, it binds its socket to that specific combination. For example, if a server listens on 0.0.0.0:8080, it means it's listening on port 8080 on all available network interfaces. If it listens on 127.0.0.1:8080, it means it's listening only on the loopback interface (localhost) for connections from the same machine. If it listens on 192.168.1.100:8080, it means it's listening on a specific IP address for connections from the local network.