Base Knowledge

Understanding TCP: Architecture, Handshakes, and Monitoring

August 14, 2026

·

6 min read

·
Understanding TCP: Architecture, Handshakes, and Monitoring

Almost every digital interaction—from loading a webpage and streaming video to querying a database—relies on network protocols operating behind the scenes. At the center of reliable internet communication sits the Transmission Control Protocol (TCP).

While higher-level application protocols like HTTP, HTTPS, and SSH get most of the spotlight, they depend entirely on the foundational guarantees provided by TCP at Layer 4 (the Transport Layer) of the OSI model. Understanding how TCP works helps engineers diagnose network latency, troubleshoot connection dropouts, and design resilient distributed systems.


What Is the TCP Protocol?

TCP is a connection-oriented, transport-layer communications protocol designed to send data packets across the internet reliably. Unlike connectionless protocols such as UDP (User Datagram Protocol), which transmit data without verifying the receiver’s state, TCP guarantees:

  • Connection-oriented communication: A formal session is established before any application data is sent.

  • Ordered data delivery: Packets arriving out of order are reassembled into the exact sequence in which they were transmitted.

  • Reliability and error checking: Corrupted packets are detected using checksums, and unacknowledged packets are automatically retransmitted.

  • Flow and congestion control: TCP regulates data transmission rates to avoid overwhelming the recipient network or host.


How TCP Connections Work

Every TCP interaction follows a distinct lifecycle: establishing the connection, transferring data, and terminating the connection.

1. The Three-Way Handshake

Before two machines exchange application payloads, they synchronize sequence numbers and establish communication parameters using a Three-Way Handshake:

  1. SYN (Synchronize): The client sends a packet with the SYN flag set and an initial sequence number (ISNcISNc​) to the server’s listening port.

  2. SYN-ACK (Synchronize-Acknowledgment): The server receives the SYN, allocates resources, and responds with both a SYN flag (with its own initial sequence number, ISNsISNs​) and an ACK flag acknowledging the client’s sequence number (ISNc+1ISNc​+1).

  3. ACK (Acknowledge): The client sends an ACK packet back to the server confirming receipt (ISNs+1ISNs​+1).

Once the server receives this final acknowledgment, the TCP socket transitions to the ESTABLISHED state, and bidirectional data transmission begins.

2. Reliable Data Transfer and Flow Control

During active communication, TCP maintains stream integrity through several internal mechanisms:

  • Sequence & Acknowledgment Numbers: Every byte transferred is numbered. The receiving host sends acknowledgments indicating the next byte it expects to receive.

  • Sliding Window Flow Control: The receiver advertises its available buffer space (the receive window) in every packet header. This prevents the sender from transmitting more data than the receiver can process.

  • Congestion Control: Senders monitor packet loss and latency variations (using algorithms like Reno, Cubic, or BBR) to dynamically adjust data throughput according to network capacity.

3. Connection Teardown and Termination

When communication ends, the connection can terminate gracefully via a four-way handshake or abruptly via a reset:

  • Graceful Termination (FIN): One endpoint sends a FIN packet. The other endpoint replies with an ACK, finishes sending any remaining data, and transmits its own FIN. The initiating host acknowledges the second FIN, and the socket closes after a brief safety timeout (TIME_WAIT).

  • Abrupt Termination (RST): If an unexpected packet arrives, a process crashes, or a port is closed, a machine sends a RST (Reset) packet to forcefully drop the connection without a multi-step teardown.


Key TCP Timing and Performance Metrics

When measuring connection health and network performance, engineers monitor three critical timing metrics:

Metric

Full Name

Description

TTDR

Time to DNS Resolved

The time taken from initial request trigger to resolving the hostname into an IP address.

TTFB

Time to First Byte

The duration between initiating a connection and receiving the very first byte of response data from the server.

RTT

Round Trip Time

The total time taken for a data packet to travel from the sender to the destination and return back.

Tracking these metrics across various geographic points allows teams to distinguish between client-side network latency, routing bottlenecks, and slow server response times.


Common TCP Connection Errors

When a TCP connection fails, the underlying socket produces specific error codes. Recognizing these codes is vital for effective incident management:

Error Code

Root Cause

resolve_host_failed

The client could not resolve the target hostname via DNS queries.

connection_refused

The destination host is reachable, but no process is listening on the specified port.

connection_timeout

The target did not respond within the allocated time window, often due to firewall rules silently dropping packets or routing failures.

connection_reset

The remote host or an intermediary firewall abruptly severed the connection by sending a RST packet.

network_unreachable

The host has no available route to the destination IP address.


Why You Must Monitor at the TCP Layer

Many engineering teams rely exclusively on top-level HTTP checks (e.g., verifying an endpoint returns HTTP 200 OK). While helpful for web apps, HTTP-only checks create blind spots:

  • Non-HTTP Infrastructure: Databases (PostgreSQL, MySQL), message brokers (RabbitMQ, Kafka), cache clusters (Redis), and custom microservices communicate over raw TCP sockets without HTTP wrappers.

  • Layer Isolation: An HTTP monitor failure might be an application crash, a TLS certificate issue, or an underlying TCP timeout. Monitoring TCP directly reveals whether the transport layer itself is accessible.

  • Port-Level Diagnostics: Verifying that specific internal and external ports accept handshakes helps detect misconfigured security groups, firewall drifts, and routing outages before they impact end users.


Active TCP Monitoring with Crystade

Diagnosing transport-layer issues requires multi-region synthetic probing and fine-grained protocol verification.

Crystade provides active health check monitoring, cron job tracking, incident management, and status pages tailored for developer and infrastructure teams.

┌─────────────────────────────────────────────────────────────┐
│                      Crystade Probes                        │
└──────────────┬───────────────────────────────┬──────────────┘
               │                               │
       Active TCP Handshake            Custom Script (DSL)
               │                               │
               ▼                               ▼
┌──────────────────────────────┐ ┌────────────────────────────┐
│      Target TCP Endpoint     │ │  Timing Metrics:           │
│  (Database, Redis, API Port) │ │  TTDR / TTFB / RTT Logs    │
└──────────────────────────────┘ └────────────────────────────┘

With Crystade, you can:

  • Execute Multi-Protocol Checks: Continuously test endpoints over TCP, UDP, HTTP/1.1, HTTP/2.0, TLS certificates, and Minecraft protocols.

  • Probe from Multiple Global Locations: Perform concurrent checks from distributed regions to detect regional routing issues.

  • Inspect Detailed Timing Breakdowns: Review immutable check logs tracking precise TTDR, TTFB, and RTT values to isolate latency spikes.

  • Run Programmable Assertions: Use lightweight, sandboxed Check Scripts written in the Rice DSL to evaluate custom criteria on every execution.

  • Manage Incidents & Alerts: Automatically trigger incident notifications and update status pages within customizable tolerable time windows.


Conclusion

The TCP protocol provides the reliability, sequencing, and flow control that modern distributed systems depend on. Understanding its internal lifecycle—from the initial 3-way handshake to connection teardown—allows engineering teams to diagnose network anomalies quickly.

Monitoring your systems directly at the TCP level ensures you catch port-level misconfigurations, firewall drops, and routing failures across all your services.

Ready to gain deep visibility into your network protocols, cron jobs, and infrastructure health? Explore Crystade and start monitoring your TCP, HTTP, and background services today.

Share this post