v9.1.1
Menu

Chapter 1: Networking Fundamentals

Master the networking concepts that power every ML API call, dataset download, and distributed training run.

Topics
8
Videos
3
Min read
66

Chapter Overview

Networking is the invisible infrastructure behind every AI system. Every model training run, every API call, every dataset download, and every distributed computation depends on reliable, performant networking. Yet many ML engineers treat the network as a black box — until something breaks and they're stuck debugging mysterious timeouts, connection refused errors, or painfully slow data transfers.

This chapter builds your networking knowledge from the ground up, starting with how data travels across the internet and ending with the specialized networking requirements of distributed GPU training. You will learn the protocols (TCP, UDP, HTTP) that your ML tools use under the hood, how to secure your model APIs with TLS and firewalls, how to efficiently transfer multi-gigabyte model files, and how to diagnose network bottlenecks that throttle your training pipelines.

By the end of this chapter, you will be able to diagnose why your SSH connection dropped, understand why your model API returns 503 errors, configure firewalls to protect GPU servers, and reason about whether your network bandwidth is sufficient for distributed training. These skills separate productive AI engineers from those who spend hours fighting infrastructure instead of building models.

Chapter Roadmap

Click any topic to jump in

Explainer video
1
How the Internet Works

Packets, IP addresses, routing, NAT — the substrate every higher-layer protocol stands on.

IP AddressesPacketsRoutingClient-Server ModelNAT (Network Address Translation)Latency vs Throughput
Layer 3 enables Layer 4

From routed packets to end-to-end transport

2
TCP/IP & UDP

Reliable byte streams vs fire-and-forget datagrams — the two transport contracts and when each one matters.

Three-Way HandshakeReliable DeliveryFlow Control & Congestion ControlUDP DatagramsTCP vs UDP for MLConnection States
3
HTTP & HTTPS

The request/response protocol that powers REST APIs, plus TLS encryption that makes the public internet safe.

HTTP MethodsStatus CodesHeadersTLS/SSL EncryptionRequest BodyKeep-Alive & HTTP/2
Two transports power application protocols
4
DNS & Domain Names

How human-readable names resolve to IP addresses, why TTLs matter, and where DNS caching can ruin your day.

A RecordCNAME RecordTTL (Time To Live)DNS CachingRound-Robin DNSPrivate DNS
5
Ports & Firewalls

Service endpoints, security groups, iptables — the gatekeepers that decide which traffic actually reaches your GPU box.

Well-Known PortsML-Specific PortsiptablesSecurity GroupsPort Forwarding & SSH TunnelingBinding to 0.0.0.0 vs 127.0.0.1
Names and gateways sit on top of IP/TCP

Resolution and access control

6
SSH & Remote Access

Key pairs, SSH config, port forwarding, rsync — the daily tools for working on remote training clusters.

SSH Key PairSSH Config FileLocal Port Forwarding (-L)SCP vs rsyncsshfsSSH Agent
7
REST APIs & gRPC

How models get served — JSON-over-HTTP for simplicity vs Protocol Buffers and streaming RPCs for performance.

REST Resource DesignJSON SerializationProtocol BuffersgRPC StreamingAPI AuthenticationRate Limiting
Encrypted shells use the same plumbing
8
Networking for ML

All-reduce, NCCL, bandwidth hierarchy, pipeline bottlenecks — where the network becomes the bottleneck in distributed training.

All-ReduceNCCLBandwidth HierarchyData Pipeline BottleneckMultipart TransfersNetwork Topology

Topics

8 topics in this chapter

You start a 40 GB dataset download on a cloud GPU server and it crawls at 3 MB/s, while the same download from another region finishes in minutes. Is the problem your instance, the cloud provider, a router halfway across the world, or the server at the other end? Without a mental model of how data actually moves, every slow transfer or unreachable server is a guess.

This chapter builds that model from the bottom up, and this first topic covers the foundation. The internet is a packet-switched network: data is cut into packets, each labelled with source and destination IP addresses, and routers forward each packet independently toward its destination. Private address ranges and NAT explain why a cloud instance has one address inside its network and another outside it.

The concepts cover IP addressing, packets and the MTU, routing and BGP, the client-server model, NAT, and the difference between latency and throughput. Later topics stack transport (TCP and UDP), HTTP, DNS, ports, SSH, APIs and distributed-training networking on top of these basics.

Definition

The internet is a global packet-switched network of independently operated networks. Hosts are identified by IP addresses, data travels as packets of at most one MTU, routers forward each packet hop by hop using tables built by routing protocols such as BGP, and NAT maps private addresses to shared public ones at network edges.

In this topic

  1. 1IP Addresses
  2. 2Packets
  3. 3Routing
  4. 4Client-Server Model
  5. 5NAT (Network Address Translation)
  6. 6Latency vs Throughput
1 of 6
IP Addresses

Every device on a network has a unique numerical label called an IP address. IPv4 uses 32-bit addresses (giving roughly 4.3 billion unique addresses), written as four octets like 192.168.1.10. IPv6 uses 128-bit addresses to solve the exhaustion problem. Cloud GPU instances typically get private IPs within a VPC and optional public IPs for SSH access.

Private address ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) are used within local networks and are not routable on the public internet. NAT gateways translate these private addresses to a shared public IP when traffic leaves the network.

Mathematical Intuition

An IPv4 address is 32 bits, giving 232≈4.29×1092^{32} \approx 4.29 \times 10^9 unique addresses — already exhausted at the global level. IPv6 uses 128 bits, giving 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38}, enough to assign roughly 6×10236 \times 10^{23} addresses to every square meter of Earth's surface. CIDR prefix length nn defines a subnet of 232−n2^{32 - n} hosts, so a /24 holds 28=2562^8 = 256 addresses (254 usable after network and broadcast).

Example:

A GPU server has the private IP 10.0.1.50 inside a VPC, and you need to SSH into it from your home network. Why can't you connect directly to 10.0.1.50?

2 of 6
Packets

Networks move data in packets rather than as one continuous stream. An Ethernet link carries frames whose payload is at most the MTU, usually 1,500 bytes. Inside that, the IP header (20 bytes for IPv4) holds source and destination addresses and a TTL, and the TCP header (20 bytes) holds ports, sequence numbers and a checksum, leaving 1,460 bytes of data. Because packets are forwarded independently, they can take different paths and arrive out of order; TCP reorders them and retransmits losses. A packet larger than a link's MTU must be fragmented or dropped, which is why mismatched MTUs cause mysterious hangs.

Mathematical Intuition

An Ethernet MTU of 1500 bytes leaves ≈1460\approx 1460 bytes of TCP payload after 20-byte IP and 20-byte TCP headers, so the protocol overhead is 40/1500≈2.7%40 / 1500 \approx 2.7\%. A 1 GB tensor at 1460 bytes per packet requires ⌈109/1460⌉≈685,000\lceil 10^9 / 1460 \rceil \approx 685{,}000 packets, each independently routed and reassembled — every lost packet triggers a retransmission of one MSS, not the whole stream.

Example:

A 2.4GB PyTorch model checkpoint needs to be downloaded from a server. Approximately how many packets will this require, assuming a standard 1500-byte MTU with 40 bytes of header overhead?

3 of 6
Routing

Routers are specialized network devices that maintain forwarding tables mapping destination IP prefixes to next-hop addresses. When a packet arrives, the router looks up the destination IP in its table and forwards it to the next router closer to the destination. The Border Gateway Protocol (BGP) allows routers across the internet to exchange routing information and find optimal paths.

The traceroute command reveals every router hop between you and a remote server, showing latency at each step. This is invaluable for diagnosing where slowdowns occur — for instance, identifying that the bottleneck in your dataset download is a congested peering point between two ISPs.

Mathematical Intuition

Routing inside one network and between networks uses different algorithms. Interior protocols such as OSPF are link-state: every router learns the full topology and runs Dijkstra's shortest-path algorithm, O((V+E)log⁡V)O((V + E) \log V) for VV routers and EE links. BGP, which connects independent networks, is a path-vector protocol: each network advertises the list of networks a route passes through, and choices follow business policy, not shortest distance. The global IPv4 table holds about a million prefixes, so routers do longest-prefix match in specialized hardware.

4 of 6
Client-Server Model

In the client-server model, one machine (the server) listens for incoming connections on a specific port, and another machine (the client) initiates a connection to request a service. The server processes the request and sends a response. This is the foundation of virtually all ML infrastructure.

ML inference APIs, model registries like Hugging Face Hub, experiment tracking servers like MLflow, and dataset hosting services all follow this pattern. Your training script acts as a client when it pulls data, logs metrics, or calls an API. When you serve a model with FastAPI or TorchServe, your machine becomes the server.

Mathematical Intuition

A server with capacity CC requests/sec and arrival rate λ\lambda has utilization ρ=λ/C\rho = \lambda / C. Queueing theory (M/M/1) says the average response time grows as 1/(C−λ)=1/(C(1−ρ))1 / (C - \lambda) = 1 / (C(1 - \rho)), which explodes as ρ→1\rho \to 1. This is why production services target ρ≈0.7\rho \approx 0.7: the last 30% of capacity buys you stable tail latency.

Example:

You have a FastAPI model server running on a GPU machine and a web application that needs to call it. Describe the client-server interaction for a single inference request.

5 of 6
NAT (Network Address Translation)

NAT translates private IP addresses to public ones at the network boundary. Your entire lab or cloud VPC might share a single public IP address. When a device with private IP 10.0.1.50 sends a packet to the internet, the NAT gateway rewrites the source address to the public IP and tracks the mapping so return traffic reaches the correct internal device.

This is why port forwarding is needed to expose services running on internal machines. Without explicit port forwarding or a public IP, external clients cannot initiate connections to a device behind NAT — they have no way to address it.

Mathematical Intuition

A NAT gateway rewrites each outbound flow to its public address and a translated source port, and it must keep those mappings unique. AWS documents that each public IPv4 address on a NAT gateway supports up to 55,000 simultaneous connections to each unique destination, and that you can associate up to 8 addresses, giving 440,000. A training job in which every worker opens many connections to the same storage endpoint can hit that limit and see connection errors, which is why VPC endpoints for S3 bypass the NAT entirely.

6 of 6
Latency vs Throughput

Latency is the time it takes for a single packet to travel from source to destination, measured in milliseconds. Throughput is the total amount of data transferred per second, measured in Mbps or Gbps. These are independent metrics — you can have high throughput with high latency (satellite links) or low latency with low throughput (a slow local connection).

Distributed training cares deeply about both. Gradient synchronization requires low latency (each GPU waits for all others), while data loading requires high throughput (streaming terabytes of training data). Understanding this distinction helps you choose the right network setup for your workload.

Mathematical Intuition

Bandwidth-delay product: BDP=bandwidth×RTT\text{BDP} = \text{bandwidth} \times \text{RTT}. Over a 10 Gbps link with 50 ms RTT, BDP=1010×0.05/8=62.5 MB\text{BDP} = 10^{10} \times 0.05 / 8 = 62.5\text{ MB} — that's the minimum window size needed to keep the pipe full. If your TCP receive window is smaller, you cap throughput at W/RTTW / \text{RTT} no matter how fat the link is.

Example:

A distributed training cluster has 100 Gbps network links with 0.5ms latency. Another has 25 Gbps links with 0.05ms latency. Which is better for (a) data-parallel gradient sync with a 350MB gradient buffer, and (b) pipeline-parallel training with frequent small tensor exchanges?

Theory Exercise

Problem:

A data scientist reports that downloading a 10GB dataset from S3 takes 20 minutes from their office but only 2 minutes from an EC2 instance in the same region. Using your knowledge of IP routing, NAT, and latency vs throughput, explain why this difference exists and suggest improvements.

Hints:
  • Consider the network path: office → ISP → internet backbone → AWS region vs EC2 → AWS internal network → S3
  • Think about how many NAT translations and router hops each path requires
  • Consider the bandwidth available on each path (office internet vs AWS internal)