Networking for Developers
Understanding the Pipes of the Internet
By Locallhost.dev Team •
Updated: January 2026 •
15 min read
Most backend issues are actually network issues. "Why can't Service A talk to Service B?" "Why is the connection timing out?" Understanding the fundamental layers of networking will save you hours of debugging.
The Models: OSI vs TCP/IP
You don't need to memorize every detail, but you do need to know where things happen.
| Layer |
OSI Name |
Developer's Reality (Examples) |
| 7 |
Application |
HTTP, HTTPS, SSH, FTP, WebSocket (Your Code lives here) |
| 4 |
Transport |
TCP, UDP (Ports live here) |
| 3 |
Network |
IP, ICMP (IP Addresses live here) |
| 2 |
Data Link |
Ethernet, MAC Addresses (Switches live here) |
Note: Layers 5 (Session) and 6 (Presentation) are often handled within the Application layer in modern web development.
TCP vs UDP: Reliability vs Speed
TCP (Transmission Control Protocol)
TCP is the polite, reliable protocol. It cares about feelings.
- Connection-oriented: Must establish a connection before sending data.
- Reliable: Ensures packets arrive. If one is lost, it resends it.
- Ordered: Ensures packets arrive in the correct order.
- Use cases: Web (HTTP/2), Email (SMTP), File Transfer (FTP).
UDP (User Datagram Protocol)
UDP is the honey badger of protocols. It doesn't care.
- Connectionless: Just starts yelling (sending data).
- Unreliable: Fire and forget. If packets are dropped, they are gone.
- Fast: Low overhead, no handshakes, no acknowledgments.
- Use cases: Video streaming, Voice over IP (VoIP), Gaming, DNS looks.
TCP: reliable + ordered + congestion control
UDP: fast + unordered + no delivery guarantee
The TCP 3-Way Handshake
Before any data is exchanged in TCP (like loading this webpage), your computer and the server perform a specific ritual.
Client (You) Server (Locallhost.dev)
| |
| ------- SYN (Let's talk!) ------------> | (Listening)
| |
| <---- SYN-ACK (Okay! I can talk!) ----- |
| |
| ------- ACK (Great! Connected!) ------> |
| |
| [Connection Established] |
| [Data Transfer Begins] |
Step 4 (Often forgotten): The 4-Way Handshake (Teardown). Connections must be closed properly (FIN packets) or you risk "Address Already In Use" errors (TIME_WAIT state).
Everything is a Socket
When you write app.listen(3000) in Node.js or Python, you are creating a Socket.
A socket is defined by: {Protocol, Local IP, Local Port, Remote IP, Remote Port}.
Socket States
- LISTEN: Server is waiting for a connection (port is open).
- ESTABLISHED: Active connection between client and server.
- TIME_WAIT: Connection closed, but waiting to ensure all packets arrived before releasing the port.
- CLOSE_WAIT: A common error state where the application hasn't properly closed the socket.
Where HTTP and TLS Fit In
HTTP is an application-layer protocol that usually runs over TCP. HTTPS = HTTP + TLS encryption.
- HTTP/1.1: One request per connection (keep-alive helps reuse).
- HTTP/2: Multiplexing multiple streams over one TCP connection.
- HTTPS: Adds a TLS handshake before HTTP starts, which can add latency but secures traffic.
Client -> TCP 3-way handshake -> TLS handshake -> HTTP request/response
Latency, MTU, and Packet Loss
Speed issues are often caused by network fundamentals, not your code.
- Latency: Time for a packet to travel. High latency causes slow APIs.
- Packet Loss: Dropped packets force retransmissions (TCP) and cause retries/timeouts.
- MTU: Maximum packet size. If mismatched, packets get fragmented or dropped.
Developer symptom: Random timeouts and flaky tests often trace back to packet loss or MTU issues in VPNs and containers.
Decoding Network Errors
ECONNREFUSED (Connection Refused)
- Result of a TCP RST packet. Usually means: Nothing is listening on that IP:Port. (Server is down or wrong port).
ETIMEDOUT (Connection Timed Out)
- The establishing packet (SYN) was sent, but no reply ever came. Usually means: Firewall dropped the packet or the IP doesn't exist.
EADDRINUSE (Address Already in Use)
- Another process is already bound to this port. Kill the other process.
ECONNRESET (Connection Reset by Peer)
- The connection was established, but the other side abruptly closed it (crashed or panic).
Retries, Timeouts, and Backoff
Robust apps assume networks fail. Use timeouts and retries carefully.
- Timeouts: Always set them for outbound HTTP calls.
- Retries: Use exponential backoff to avoid thundering herds.
- Idempotency: Only retry requests that are safe (GET, PUT with idempotency keys).