00
Skip to main content
← All posts
The Network Under the Hood: A Developer's Refresher with Wireshark
30 Oct 20266 min readNetworking · Wireshark · TCP/IP · Performance

The Network Under the Hood: A Developer's Refresher with Wireshark

When curl hangs or your API latency spikes, high-level logs only tell half the story. Here is a practical, packet-level walkthrough of TCP handshakes, TLS 1.3 negotiation, and connection debugging inside Wireshark.

I spent a week blaming Postgres for an API that took 280ms. Query plans, indexes, EXPLAIN ANALYZE — nothing explained it. Then I opened Wireshark and saw three round-trips of DNS + TCP + TLS burning before my backend ran a single line of code.

Most days we live at the top of the OSI model: fetch(), Axios, FastAPI routes, console.log. It feels like clean JSON and status codes — until a pipeline throws ECONNRESET at 3 AM or a webhook silently drops during peak load.

Datadog tells you that a request failed. It never tells you why at the transport layer. For that, you look at the wire.


Why the wire, not the logs?

Wireshark captures raw packets off your NIC and decodes them into readable protocol trees. You do not need a telecom degree to get value from it — knowing four filters and three handshakes already puts you ahead when debugging distributed systems.


Step 0: The Developer's Filter Cheat Sheet

When you open Wireshark and click your active interface (e.g., Wi-Fi or en0), the screen will flood with thousands of packets per second.

The secret to not drowning in noise is Wireshark's Display Filters:

| Filter | What It Shows | | :--- | :--- | | tcp.port == 443 | All HTTPS traffic on port 443 | | dns | Domain name queries and responses | | http || http2 | Unencrypted HTTP and HTTP/2 frames | | tls.handshake.type == 1 | TLS Client Hello packets (see SNI hostnames) | | tcp.analysis.flags | Problems: Retransmissions, Dup ACKs, Zero Windows | | ip.addr == 1.2.3.4 | Filter strictly to one server IP |


1. The Invisible Cost: The DNS Resolution

Before your client can send a single byte of HTTP data, it needs an IP address.

Type dns in the filter bar and trigger a simple terminal request:

curl -I https://api.github.com

In Wireshark, you will immediately see two UDP packets on port 53:

  1. Standard query (A/AAAA): Your OS asks the resolver: "What is the IPv4/IPv6 address for api.github.com?"
  2. Standard query response: The DNS resolver returns the IP addresses along with a TTL (Time to Live).
DNS 82 Standard query 0x1a2b A api.github.com
DNS 98 Standard query response 0x1a2b A 140.82.121.4

Developer Lesson: If your application microservices do not cache DNS lookups (common in poorly configured Node.js environments where the default DNS lookup is uncached and synchronous), you are paying a 20ms–80ms penalty on every single external API request.


2. The Sacred Ritual: TCP 3-Way Handshake

Once the IP is known, your client must establish a reliable stream over TCP.

Filter by tcp.flags.syn == 1 to watch the handshake unfold:

Packet 1: Client -> Server [SYN]       Seq=0 Win=65535 MSS=1460 SACK_PERM=1
Packet 2: Server -> Client [SYN, ACK]  Seq=0 Ack=1 Win=65535 MSS=1460
Packet 3: Client -> Server [ACK]       Seq=1 Ack=1 Win=65535

Let's break down what just happened:

  1. SYN: The client picks an initial sequence number (Seq=0 relative) and announces its parameters—notably MSS (Maximum Segment Size), usually 1460 bytes for standard Ethernet MTU of 1500 bytes.
  2. SYN-ACK: The server acknowledges the client's sequence number (Ack=1) and provides its own initial sequence number.
  3. ACK: The client acknowledges the server's sequence number.

The Round-Trip Tax (RTT)

The handshake takes 1 full Round-Trip Time (RTT).

  • If your server is in the same datacenter: ~0.5ms.
  • If your client is in Cairo and the server is in Frankfurt: ~55ms.
  • If your client is in London and the server is in Sydney: ~280ms.

Before transmitting any application logic, you have already spent 1 RTT just establishing the transport channel.


3. The Encryption Layer: TLS 1.3 Handshake

Because we requested HTTPS, the TCP connection is not enough; we need cryptographic session keys.

Filter by tls:

In TLS 1.2 (legacy), establishing encryption took 2 full round-trips. In TLS 1.3 (modern standard), this is streamlined into 1 round-trip:

Packet 4: Client -> Server  TLSv1.3  Client Hello
Packet 5: Server -> Client  TLSv1.3  Server Hello, Change Cipher Spec, Application Data
Packet 6: Client -> Server  TLSv1.3  Application Data (Encrypted HTTP payload)
  1. Client Hello: The client sends supported cipher suites, key shares (Diffie-Hellman parameters), and the SNI (Server Name Indication).
  2. Server Hello: The server picks the cipher, generates its matching key share, and immediately begins sending encrypted certificates and verification.
  3. Application Data: Both parties now possess shared session keys. The HTTP request is encrypted and transmitted.

Total Connection Cost:

$$\text{Total Time to First Byte (Cold Connection)} = \text{DNS} + \text{TCP (1 RTT)} + \text{TLS 1.3 (1 RTT)} + \text{HTTP Request/Response (1 RTT)}$$

On a fresh connection across regions, that can easily total 300ms–500ms before your backend server has even executed a single line of application code!

Developer Lesson: This is why HTTP Keep-Alive / Connection Pooling is mandatory in production. Reusing an existing socket avoids the TCP and TLS handshakes entirely, dropping connection establishment time from ~200ms to 0ms.


4. Catching Real Production Bugs in Wireshark

Here are the three most common production network bugs you will diagnose with packet captures:

1. TCP Retransmissions (tcp.analysis.retransmission)

When a sent packet is not acknowledged within the retransmission timeout (RTO), TCP re-sends it.

  • Symptom in Code: Sudden spikes in API latency (often in jumps of 200ms, 1s, 3s).
  • Diagnosis: Packet loss on the wire, Wi-Fi interference, or congested egress routers.

2. TCP Zero Window (tcp.analysis.zero_window)

Every TCP packet advertises a Win (Window Size), telling the sender: "I have X bytes of buffer space remaining."

  • If you see TCP ZeroWindow, the receiver's OS buffer is completely full!
  • Symptom in Code: Uploads or streaming responses freeze completely.
  • Diagnosis: The receiving server's application thread is blocked (e.g., synchronous CPU loop or event loop lag in Node/Python) and isn't reading bytes from the socket fast enough.

3. Idle Timeout Resets (tcp.flags.reset == 1)

A RST packet forcefully tears down a connection without a graceful FIN handshake.

  • Symptom in Code: Error: read ECONNRESET or 502 Bad Gateway.
  • Diagnosis: Classic keep-alive mismatch. If your AWS ALB idle timeout is set to 60 seconds, but your Node.js or Gunicorn backend has an idle timeout of 50 seconds, the backend will send a RST right as the load balancer routes an incoming user request to that socket.

Summary Checklist for Engineers

  1. Inspect Before Guessing: When performance or connectivity fails intermittently, open Wireshark or run tcpdump -w trace.pcap on your server.
  2. Pool Your Connections: Ensure your HTTP clients (Axios, requests, Go http.Client) have connection pooling enabled with an appropriate max-idle pool size.
  3. Align Timeouts: Ensure upstream proxy timeouts (NGINX, Cloudflare, ALB) are strictly shorter than your application server's keep-alive timeout.
  4. Upgrade to TLS 1.3 & HTTP/2: Cut handshake latency in half and multiplex concurrent requests over single sockets.

High-level frameworks come and go, but the packets never lie.