My Computer maths200 699. videos 306. toy 307. blocks
untitled

My Computer

All30 cs3008cs6009maths20012maths4001
Address
NameSizeTypeDate
25 object(s)
My Computer

605. networking

🔍
Aa

Networking


At its core, networking is just tagging data with the right addresses and letting the network deliver it. The concept is one sentence, but the failure modes fill textbooks: packets arrive out of order, links congest, addresses exhaust, adversaries forge labels. The layered protocol stack and the protocols within each layer exist to solve these problems reliably at scale.

I


1.1. Switching & Multiplexing

Given a network is a graph of nodes joined by links (e.g. the copper pair, the fibre strand) that exchange data under shared protocols, many sources contending for finite link capacity poses two problems, i) path selection: the route by which data traverses intermediate nodes from source (SRC) to destination (DST); and ii) link sharing: how multiple transmissions divide a single physical link. Switching answers the first and multiplexing the second. How a link of capacity $C$ is partitioned among competing flows is what distinguishes the switching methods and governs the resulting throughput, latency, and loss.

Specifically, given that multiplexing admits i) time-division multiplexing (TDM): each flow transmits in a fixed time slice; ii) frequency-division multiplexing (FDM): each flow occupies a separate frequency band; and iii) statistical multiplexing: flows share capacity on-demand without pre-allocation; circuit switching leverages TDM/FDM and reserves resources (e.g. bandwidth) for the connection’s lifetime irrespective of utilisations. For example, the public switched telephone network (PSTN), where each call reserves a dedicated circuit, suits steady voice calls though it reveals the approach’s fundamental inefficiency for bursty, short-lived computer traffic.

Packet switching instead adopts statistical multiplexing, partitioning data into packets that share the link on-demand for near-maximum utilisation. Each packet carries its own destination address, and a store-and-forward packet switch forwards it hop-by-hop by matching that address against a lookup table to select the next hop, a role realised at multiple layers. The per-packet latency can be decomposed as $d_{\text{total}} = \sum_{i=1}^{N}(d_{\text{proc}} + d_{\text{queue}} + d_{\text{trans}} + d_{\text{prop}})_i$, where $N$ is the number of hops, $d_{\text{trans}} = L/R$ (i.e. push $L$ bits onto the link at rate $R$), and $d_{\text{prop}} = d/s$ (i.e. signal traverses link of length $d$ at speed $s$), whilst $d_{\text{proc}}$ (e.g. header lookup, checksum) and $d_{\text{queue}}$ (e.g waiting behind other packets) are non-deterministic.

1.2. Network Models

Networks are also classified by geographic scope, in increasing span local area network (LAN), metropolitan area network (MAN), and wide area network (WAN). A LAN spans a building/campus at high bandwidth and sub-millisecond latency, predominantly over Ethernet. A MAN spans a city, a WAN spans countries or continents, interconnecting many LANs. Over WAN distances, $d_{\text{prop}} = d/s$ dominates, fixed by distance and signal speed, hence irreducible by bandwidth (a transatlantic round trip costs tens of ms), whereas LAN latency is transmission-bound. ARPANET (1969), the first packet-switched WAN, grew into the foundation of the modern internet.

The open systems interconnection (OSI) model, set by international organisation for standardisation (ISO, 1977-84), has seven layers with strict separation of concerns. Designed by committee ahead of implementation, its protocol suites (e.g. X.400 for email, X.500 for directory services) proved over-specified and costly to implement. TCP/IP however took the opposite approach: implement and standardise what works. As a consequence, the US government also abandoned its OSI mandate (GOSIP, 1990) by 1995. Though OSI lost as a protocol suite, its layer numbering persists as standard vocabulary.

The transmission control protocol / internet protocol (TCP/IP) model was developed through running implementations on ARPANET (NCP → TCP/IP on 1 January 1983, Flag Day), prevailing by shipping working code ahead of the specification. It stacks four layers: i) link: frame transmission over a physical medium; ii) internet: logical addressing and best-effort routing; iii) transport: end-to-end process-to-process communication; and iv) application: user-space service semantics. This embodies the end-to-end principle (1984), which holds that application-specific functions should reside at the endpoints rather than in the network, with $\text{L}2$ to $\text{L}4$ implemented in the kernel and $\text{L}1$ in the NIC.

Each layer encapsulates the unit above as opaque payload and prepends only its own header, producing its protocol data unit (PDU), e.g. { $\text{L}1$: bits on the wire, $\text{L}2$: a frame, $\text{L}3$: a packet, $\text{L}4$: a segment (TCP) or datagram (UDP), $\text{L}7$: a message or data}. The receiver decapsulates this in reverse by stripping headers layer-by-layer. The isolation lets each layer evolve independently, so Wi-Fi replaces Ethernet at $\text{L}2$, or IPv6 replaces IPv4 at $\text{L}3$ without disturbing the others. Encapsulation also fixes which addresses survive the journey. Delivery is addressed per link at $\text{L}2$ but end-to-end at $\text{L}3$, so a frame’s MAC addresses are rewritten at every hop while the packet’s IP addresses hold from source to destination, and the $\text{L}4$ port names the process the bytes are finally handed to.

1.3. Ethernet [L1/L2]

Given IEEE 802 splits $\text{L}2$ into logical link control (LLC, 802.2) and media access control (MAC) sublayers to expose one interface to $\text{L}3$ over many media, Ethernet (IEEE 802.3, 1983) spans the MAC sublayer, where it frames, and $\text{L}1$, where it encodes the bits into signals. A frame is the payload with SRC and DST MAC addresses prepended, each a 48-bit identifier assigned to a network interface card (NIC), and a CRC-32 checksum appended. At $\text{L}1$, the physical layer serialises this frame onto the medium through a line code that guarantees clock recovery. The name ‘Ethernet’ comes from Metcalfe’s 1973 nod to the ‘luminiferous ether’ the medium once believed to carry light.

The maximum transmission unit (MTU) denotes the largest L3 packet transmissible in a single frame on a link (i.e. one hop) exclusive of the L2 header and CRC. For example, Ethernet and Wi-Fi admit $1500\ \text{B}$ while a cellular link often admits less. As a packet includes its IP and $\text{L}4$ headers, the payload is bounded by $\text{payload}_{\text{L4}} \leq \text{MTU} - H_{\text{IP}} - H_{\text{L4}}$ (e.g. $1460\ \text{B}$ for TCP over IPv4). Along a path however the smallest MTU governs. A larger packet is split or dropped on the way unless the sender determines its minimum by path MTU discovery. Data centre and GPU-cluster fabrics raise the MTU to $9000\ \text{B}$ (jumbo frames) to cut header overhead on distributed-training transfers.

A MAC address uses six hex octets (e.g. 00:07:E9:65:F5:43) and is globally unique. The first half is an organisationally unique identifier (OUI) the IEEE assigns to a vendor and the rest are a serial number the vendor assigns to each NIC. Yet Wi-Fi MAC randomisation sets the 2nd-lowest bit of the first octet to mark the address as locally administered. While whom a frame names is its DST MAC address, the lowest bit of its first octet distinguishes the types, i) unicast: a clear bit, one NIC; ii) multicast: a set bit, the subscribers of a group; and iii) broadcast: all 48 bits set, every node. In these terms terrestrial TV is a broadcast, IPTV a multicast, and Netflix a unicast per viewer.

An L2 switch is the device that joins the NICs of a network. Each frame leaves the switch through the physical port (i.e. jack) whose cable reaches its DST MAC. Chained together such switches form a broadcast domain, the nodes one broadcast reaches, across which a frame passes unaltered as no switch reads past its header. For each frame the egress port comes from a forwarding table each switch self-learns (IEEE 802.1D) from the SRC MAC and ingress port of frame. A host in practice holds only its next hop’s IP, hence its kernel resolves the MAC by the address resolution protocol (ARP), a request for that IP broadcast across the domain and answered by its holder.

Ethernet is one $\text{L}2$ protocol among many. Namely, their frames satisfy $F_{\text{Ethernet}} \neq F_{\text{Wi-Fi}} \neq F_{\text{cellular}}$, where the first two share the 48-bit MAC. For instance, a home network is one broadcast domain in which an access point bridges Ethernet and Wi-Fi, whereby a laptop on Wi-Fi discovers a wired printer by broadcast whereas a phone on cellular cannot. Such a domain is bounded by its $\text{L}3$ router whose MAC is the destination of every leaving frame. A MAC though merely names a NIC on one link. An IP instead names a host across its network, hence it alone spans links that share neither frame nor address and is the lowest address a program holds.

II


2.1. IP [L3]

Internet protocol (IP, RFC 791, 1981) is a standard at $\text{L}3$ that names every host in one address space. The SRC and DST IP addresses sit in a packet header that routers read to forward it across any link. It is a fixed-length identifier of a host’s network interface, standardised in requests for comments (RFCs) under the internet engineering task force (IETF), and represented as 32-bits in IPv4 or 128-bits in IPv6 (RFC 2460, 1998). IP guarantees neither arrival nor order, leaving both to $\text{L}4$, yet it suffices to join any set of networks by routers into an internet (inter-network). Namely, the Internet is the global instance grown from ARPANET, connecting 6 billion users (74%, ITU 2025).

Formally put, a router is the $\text{L}3$ realisation of the packet switch which stitches heterogeneous $\text{L}2$ networks into one internet. The former is itself a computer whose kernel forwards, as does a host’s with forwarding enabled, whereas a switch is silicon that never runs one. For instance, on every inbound packet, a router strips the frame, reads the DST IP, looks up the next hop, decrements the time-to-live (TTL), and re-frames to that hop’s MAC. The work is the data plane and building the table the control plane. For every outbound packet, a host consults the kernel’s routing table, whose default entry names its default gateway (i.e. usually a single router) as the next hop off-subnet.

A table indexed by host would grow linearly in hosts, up to $2^{32}$ entries, with every router updating as any host moved. As a remedy, IPv4 partitions the address space by a network prefix, which splits each address into prefix and host (e.g. 192.168.1 and 7 in 192.168.1.7), so a table holds one entry per network. Yet a uniform partition ill fits networks of unequal size. Classful addressing (RFC 791, 1981) therefore read from an address’s leading bits a prefix length $n \in \lbrace 8, 16, 24 \rbrace$, such that a Class A, B, or C network holds $2^{32-n} - 2$ hosts (16M, 65k, or 254). An organisation of 500 hosts still outgrew a Class C for a Class B that wasted addresses and kept all in one broadcast domain.

Subnetting (RFC 950, 1985) further split a classful network into subnets, each its own broadcast domain, by using a subnet mask $m$ of $n$ leading $1$s (e.g. /24 is 255.255.255.0) in which each bit doubles them and halves hosts. A subnet is then an equivalence class under $x \sim y$ iff $x \land m = y \land m$, while a host recovers each side by bitwise AND ($\land$) of an address with $m$. Hosts can exchange frames via $\text{L}2$ switches alone within a subnet yet need a router to leave it. Classless inter-domain routing (CIDR, RFC 1519, 1993) retired the address classes and carries $n$ with every route instead. Consequently, any $n$ is allowed and two sibling /$n{+}1$ prefixes merge into their parent /$n$ as one route.

Prefixes are delegated downward, from one central registry to five regional ones to ISPs to their customers, so a customer’s prefix nests in its provider’s. Since a /$n$ prefix is an aligned block of $2^{32-n}$ addresses, any two are disjoint or nested, hence the routing table entries matching a destination form a chain and the longest-prefix match, the chain’s most specific element, is well defined, with a default route (0.0.0.0/0) as the coarsest fallback. Routers learn these entries by open shortest path first (OSPF) within an autonomous system (AS), one operator’s network, and by border gateway protocol (BGP) between ASes. Each delegation draws on one finite pool.

A pool of cardinality $2^{32}$ proved insufficient even under CIDR. The stopgap is the private address (RFC 1918, 1996) in the reserved blocks {10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16}, which is local to its LAN as a loopback address (127.0.0.0/8, RFC 1122, 1989) is to its host, and need not be unique across LANs. A router maps each outbound packet’s source $($private IP, port$)$ injectively to $($public IP, port′$)$ via network address translation (NAT) and port address translation (PAT), then inverts the map on replies. By construction no external host can connect inward unless the router is told the target host. IPv6 now replaces the pool with one of $2^{128}$ since the stopgap ended in 2011.

2.2. TCP [L4]

Given that IP is not responsible for reliability, transmission control protocol (TCP, RFC 675 1974; RFC 793 1981, now RFC 9293 2022) provides reliable, ordered, byte-stream delivery over an unreliable packet-switched network. A TCP connection is identified by a 4-tuple (src IP, src port, dst IP, dst port), each endpoint denoted IP:port (e.g. 127.0.0.1:8080), where ports are 16-bit integers (0-1023 reserved) that multiplex a single IP to distinct processes. A client, unlike a server, binds no port and takes an ephemeral port the kernel assigns. Before any byte can be numbered both ends must agree where numbering starts, over a network that delays and duplicates, which is why connection establishment takes three messages and not two.

In the three-way handshake (3WHS) the client sends SYN with initial sequence number (ISN) $x$, the server replies SYN-ACK with ISN $y$ and ACK $x+1$, and the client completes with ACK $y+1$, each side’s ISN explicitly acknowledged, costing one RTT before data transfer. Teardown uses a four-way FIN exchange. The same delayed-duplicate hazard outlives the connection, since a straggler segment from a closed connection could be taken for one from its successor on the same 4-tuple, so the closing side holds TIME_WAIT for $2 \times$ MSL (maximum segment lifetime). Each incarnation also begins from a distinct ISN, derived cryptographically (RFC 6528) to resist off-path sequence prediction.

A connection is not yet reliable delivery, as IP beneath it may drop or reorder packets, and TCP reconstructs the ordered stream from sequence numbers and acknowledgements, numbering each byte in the stream so the receiver can return cumulative ACKs naming the next byte it expects. The stream carries no message boundaries, since a send() may arrive split or merged, so every application protocol frames its own messages. The sender holds a sliding window of unacknowledged data and retransmits segments not acknowledged within the retransmission timeout (RTO), but the right timeout cannot be fixed in advance when RTT varies by path and by congestion, so Jacobson’s algorithm estimates it from smoothed RTT and its variance.

Waiting out even a well-estimated timer is slow, and the stream itself signals loss earlier, since every out-of-order arrival makes the receiver repeat the ACK for the last in-order byte, so fast retransmit resends on three such duplicate ACKs, cutting recovery from hundreds of milliseconds to roughly one RTT. A cumulative ACK still cannot say which later blocks arrived, forcing retransmission of data the receiver may already hold, and selective acknowledgements (SACK, RFC 2018), negotiated as a header option in the handshake, close that last gap by reporting the received ranges so the sender resends only what is missing.

Reliable delivery can still overwhelm its receiver or the network, two distinct problems with two distinct mechanisms. Flow control protects the receiver through a receiver-advertised window (rwnd), whereas congestion control protects the network through a congestion window (cwnd), and the sender transmits at $\min(\text{rwnd}, \text{cwnd})$, so the tighter constraint always governs throughput. The receiver can state its window outright, but the network cannot, so cwnd must be probed, a lesson learned from the 1986 internet congestion collapse and formalised by Van Jacobson in 1988.

Slow start initialises cwnd $= 1$ maximum segment size (MSS) and doubles it each RTT until threshold ssthresh, beyond which congestion avoidance applies additive increase/multiplicative decrease (AIMD), one MSS per RTT up and halving on loss. CUBIC (Linux default since 2006) replaces AIMD’s linear increase with a cubic function $W(t) = C(t - K)^3 + W_{\max}$, growing the window faster on high bandwidth-delay paths, while BBR (Google, 2016) drops loss as the congestion signal altogether, since loss appears only after the bottleneck buffer has already filled and delay has already risen, instead estimating bottleneck bandwidth and minimum RTT and pacing packets to match capacity.

A socket (BSD 4.2, 1983) is a communication endpoint exposed as a file descriptor, created with an address family and a socket type. The address family determines what the socket is bound to, AF_UNIX for a local filesystem path (§603#3.1, UDS) or AF_INET for an (IP, port) pair, or AF_INET6 for IPv6, which on a dual-stack kernel also accepts IPv4 clients as v4-mapped addresses (::ffff:a.b.c.d) unless IPV6_V6ONLY is set, and the socket type the delivery semantics, SOCK_STREAM for reliable byte streams (TCP) or SOCK_DGRAM for best-effort datagrams (UDP). This single API unified local and network IPC, extending the fd interface (§603#3.3) to network endpoints.

In socket programming a TCP server creates a socket, calls bind() to attach it to a local (IP, port), then listen() to mark it as a passive socket that accepts incoming connections, whereas a client’s connect() sends the SYN that opens the handshake. The kernel then completes handshakes by itself, parking established connections in an accept queue bounded by the listen backlog, and each accept() call dequeues one (blocking while the queue is empty), returning a new connected fd for that client’s 4-tuple, which is why §604#1.1’s thread-per-connection model spawns one thread per accept(). Higher-level libraries (e.g. Python’s requests) abstract this entirely, calling down through urllib3 → socket module → POSIX socket API → kernel TCP/IP stack.

2.3. UDP [L4]

Where TCP layers reliability, ordering, and flow control over IP, user datagram protocol (RFC 768, 1980) keeps IP’s best-effort, connectionless delivery and adds almost nothing but ports and a checksum. Its header is only 8 bytes (source port, destination port, length, checksum), compared to TCP’s minimum 20-byte header, and there is no handshake, no acknowledgement, no retransmission, no ordering guarantee, and no flow or congestion control. The omission is the design, as TCP fixes one reliability policy for every application, whereas UDP delivers the kernel’s minimum and leaves the policy to the process that knows its own tolerance for loss.

Each canonical UDP application declines reliability for a different reason. DNS fits the typical request-response exchange in a single datagram, and the one RTT saved by skipping the three-way handshake matters for a service invoked before every HTTP connection. Real-time voice and video drop rather than retransmit, since an audio frame arriving 200 ms late is worse than a gap. Dynamic host configuration protocol (DHCP, RFC 2131) has no choice at all since a joining host holds no IP to open a connection from and so must broadcast a datagram. The application either tolerates loss, implements its own selective reliability, or treats the latest packet as the only one that matters.

A datagram is bounded above at 65,535 bytes by UDP’s 16-bit length field, though the operative bound is the path MTU. An IPv4 packet exceeding it is fragmented at the IP layer, and losing any one fragment forces retransmitting the whole datagram, while IPv6 routers never fragment, dropping the packet and signalling the source instead. A UDP application therefore keeps each message within the MTU, which is why DNS falls back to TCP when a UDP response is truncated, historically above 512 bytes though EDNS(0) permits up to 4096, with ~1232 the fragmentation-safe default since DNS Flag Day 2020.

Declining TCP also declines its congestion control, so a UDP application sending at full rate risks congestion collapse, useful throughput sinking under retransmissions, obliging a well-behaved sender to pace itself. The same absence read the other way is UDP’s lasting value, as a bare datagram service is the substrate on which new transports are built in user space, needing no kernel or middlebox to change. QUIC rebuilds reliability, congestion control, and encryption there to carry HTTP/3, so the transport that adds almost nothing now underlies a growing share of the web.

III


3.1. DNS (+ CDN) [L7]

Transport carries bytes between numeric addresses, so the application layer begins with the service that turns a name into an address. Domain name system (RFC 1035) (DNS, 1987) is a hierarchical, distributed system resolving domain names to typed records, served over port 53. A query dig google.com A triggers a recursive resolver to resolve the domain through, i) 13 root server clusters identify the top-level domain (TLD) where anycast routes a query to the nearest instance sharing one IP; ii) the TLD server delegates to the domain’s nameserver; and iii) the authoritative nameserver provides an A record (IPv4). Each response carries a TTL bounding its cache life.

DNS record types extend beyond A records, including AAAA (IPv6), CNAME (alias), MX (email routing), TXT (domain verification), and SRV (service host, port, priority). In particular, CNAME records enable content delivery networks (CDNs), where a domain’s CNAME redirects resolution to the CDN’s namespace and anycast returns the nearest point of presence (PoP). Providers such as Cloudflare (~330 cities), Akamai (~4,100 PoPs), and CloudFront (~750 PoPs) operate using HTTP caching headers (Cache-Control, ETag) to govern freshness across them, while the PoP serves cached content directly and falls back to the origin on a cache miss.

Unencrypted and unsigned, DNS admits cache poisoning, an off-path attacker racing the legitimate reply with a forged one the resolver then serves for the TTL’s duration. The 2008 Kaminsky attack made the race winnable within seconds through the 16-bit query ID alone. DNS security extensions (DNSSEC) address integrity, as each zone signs its records and the parent signs the child’s key, a chain of signatures from the root the resolver verifies before caching. DoH (DNS over HTTPS) and DoT (DNS over TLS) instead address confidentiality, encrypting the stub-to-resolver hop so an on-path observer cannot read queries, though the resolver itself still sees every lookup.

3.2. The Web [L7]

By 1989 the internet was two decades old, yet the two capabilities a web of documents would need still sat in separate systems, i) reach: crossing to a document on another machine; and ii) linking: an inline jump to another document. Reach existed without linking. FTP (1971) and email over SMTP (1982) moved documents across machines as flat files, no links. Linking existed without reach. It began with the Memex (1945) in As We May Think , a microfilm desk whose associative trails linked documents. Apple’s HyperCard (1987) made hypertext mainstream, but its links never left one machine, unable to name documents elsewhere. No system held both.

At CERN, physicists on incompatible machines lost documents across unlinked systems. Tim Berners-Lee’s 1989 memo Information Management: A Proposal joined the two halves with three pieces, i) hypertext markup language (HTML): a document format carrying inline links; ii) uniform resource locators (URLs): one scheme naming any document on any host; and iii) hypertext transfer protocol (HTTP): the protocol transferring it; The result, the world wide web (WWW, W3), is an $\text{L}7$ space of linked documents addressed by URL, one application over the internet, not the internet itself. So both are webs, the internet of networks and the web of documents.

While HTML structures a document into headings, paragraphs, and lists, its anchor element places a link anywhere in the running text. Any page can then reference any other on any host, forming a graph rather than a tree. The first browser to render it, WorldWideWeb editor (later renamed as Nexus) on a NeXT machine (1990), even displayed images inline, but only through the NeXT’s own text system, so that ability stayed bound to the platform and was lost once the browser was ported to others. Markdown (2004), a lighter markup language John Gruber designed, compiles to this same HTML while remaining readable as unrendered plain text.

A rival briefly looked likelier to win. Gopher (1991, University of Minnesota) appeared just after the web, was likewise networked, and presented documents through nested menus, spreading faster for a year or two. The two differed not in protocol, since gopher and HTTP are near-twin request-response protocols, but in document model. Gopher stored documents as plain text and confined links to the menus, giving it the tree structure of a filesystem (§603#3.3) or code repository, navigated by drilling down and back up. Its native clients spoke only gopher://, never the web’s http://.

The web soon overtook its rival on two fronts. In 1993 Minnesota’s licensing fees drove adoption off Gopher while CERN placed the web in the public domain, and Mosaic rendered inline images on commodity hardware, a medium richer than text-only Gopher that Netscape (1994) carried to the mass market. Because a URL’s scheme names the protocol, these browsers dispatched ftp://, mailto:, and gopher:// from one address bar, subsuming the rival rather than merely beating it. A fragment of Gopher endures there nonetheless, as Mark McCahill, one of its Minnesota creators, co-authored the URL specification (RFC 1738, 1994) and is credited with coining the term.

The same inline links became the web’s retrieval problem, as a corpus grown to millions shifted the constraint from reach to relevance. Directories like Yahoo and keyword engines like AltaVista answered poorly, the one bounded by editors, the other gamed by repeated terms. Google’s PageRank (1998) instead exploited the hyperlink graph, weighting each inbound link by its source’s rank, equivalently the stationary distribution of a random walk made irreducible and aperiodic (hence ergodic, §212) by a damping term teleporting to a uniformly random page. The link an author placed for a reader thus doubled as a machine’s ranking signal.

3.3. HTTP [L7]

An HTTP request opens in plain text with a start line naming the method, target URL, and protocol version, then header lines of key-value metadata and an optional body, and the response mirrors it with a status line, headers, and body. The target decomposes as scheme://host:port/path?query, its host resolved through DNS, a framing readable enough to inspect with curl or telnet. Headers form the protocol’s extensibility surface, the mandatory Host letting one IP serve many domains through virtual hosting, Accept and Content-Type driving content negotiation over the representation and its media type, and Accept-Encoding selecting compression (gzip, brotli).

HTTP is stateless by design, the server retaining no memory between requests, so applications must carry state explicitly. Cookies carry a session ID, while bearer tokens like a JSON web token (JWT) ride the Authorization header, both threading client state. The session ID indexes server-side state, whereas a JWT carries signed claims inline, sparing the lookup but resisting revocation. Status codes partition responses into five classes by the leading digit (1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error), of which 200, 301, 404, and 503 dominate debugging.

HTTP/1.0 (RFC 1945, 1996) opened a new TCP connection per request, each paying the handshake’s round-trip and re-entering slow start with a cold congestion window. HTTP/1.1 (RFC 2068, 1997) added persistent connections and pipelining, but a response carries no identifier naming its request, so order is the only correlation and answers must return in sequence, whence pipelining suffered head-of-line blocking, one slow response stalling those behind it. Browsers disabled pipelining and opened ~6 parallel connections per origin, and sites split assets across subdomains (domain sharding) to multiply the cap, every shard paying its own handshake and cold window.

HTTP/2 (RFC 7540, 2015) multiplexed streams over one TCP connection, yet a lone lost segment stalled every stream at once (transport-layer head-of-line blocking). HTTP/3 (RFC 9114, 2022) dissolved this with QUIC (Google, 2012, standardised 2021 as RFC 9000), reimplementing TCP’s reliability per stream rather than per connection, so a lost packet stalls only the stream it belongs to, and TLS 1.3 encryption over UDP for 1-RTT establishment (0-RTT on resumption). The progression tracks protocol ossification, TCP so embedded in middleboxes that it proved immutable, forcing innovation onto UDP.

Applications sometimes require server-initiated data, but HTTP/1.x is strictly request-response, with the client initiating every exchange and only one in flight at a time per connection. Long polling (~2006, Comet) simulated server push by holding requests open, wasting one TCP connection per pending event. Server-sent events (SSE, W3C 2015) solved it with persistent unidirectional streaming over a single HTTP connection (e.g. LLM token streaming). WebSocket (RFC 6455) (2011), by contrast, uses an HTTP Upgrade handshake to switch to a full-duplex protocol over TCP, which supports bidirectional use cases (e.g. Slack, Figma).

3.4. HTTPS [L7]

HTTP transmits plaintext, exposing traffic to any observer on the path. Transport layer security (TLS), evolved from Netscape’s Secure Sockets Layer (SSL, 1995, now obsolete), provides confidentiality, authentication, and integrity over TCP, and HTTPS is simply HTTP spoken inside a TLS tunnel (i.e. port 443). In TLS 1.3 (RFC 8446, 2018), the client and server exchange cipher suite preferences and ECDHE key shares in a single round-trip, deriving a shared secret and verifying the server’s identity via its X.509 certificate. Resumed connections support 0-RTT by reusing a cached pre-shared key, trading replay vulnerability for zero-latency establishment.

Encryption alone would still leave an impostor holding the other end, so the server’s identity rests on a certificate chain of trust, where the server presents a certificate signed by an intermediate CA (Certificate Authority), itself signed by a root CA pre-installed in the client’s trust store. The client validates each signature and checks the hostname against the certificate’s names. The handshake then binds the certificate to the live session, as the server signs a transcript of its messages with the certificate’s private key (i.e. CertificateVerify), so a stolen certificate without its key cannot impersonate the server.

Trust so anchored is only as durable as the key it names, a hazard Heartbleed (2014) made concrete when a buffer over-read in OpenSSL let anyone extract a server’s private key, rendering traffic recorded under static-RSA key exchange retroactively decryptable. TLS therefore achieves forward secrecy through ephemeral key exchange, each session generating a unique Diffie-Hellman key pair discarded after the handshake, so a compromised long-term key cannot decrypt past traffic, and TLS 1.3 mandates ephemeral exchange and removes static RSA.

Validation failures are the common operational errors, where SSL: CERTIFICATE_VERIFY_FAILED or ERR_CERT_AUTHORITY_INVALID typically indicates an expired certificate, a hostname mismatch, or a missing intermediate, and curl -v or openssl s_client reveals the full handshake for debugging. Issuance itself is automated by ACME (RFC 8555), the protocol behind Let’s Encrypt, which proves domain control through an HTTP or DNS challenge and issues short-lived 90-day certificates that a daemon renews, making HTTPS the default rather than a purchased add-on.

IV


4.1. Application Programming Interface

The application programming interface (API) is the contract by which one program exposes its operations to another. Within a single process it is no more than a shared function signature. A networked service instead stretches the contract across a process or machine boundary, where the stack carries the payload as bytes, reliably at best (TCP, §2.2) and never interpreted, leaving what they mean for the two endpoint programs to settle. That agreement runs along two axes. i) format: how the data is represented, swappable while the operations hold, hence interchangeable; and ii) style: the operations and their semantics, pinned in both ends in advance, and so architecturally decisive.

The format axis begins a step below the formats, at serialisation, the flattening of an object into a self-contained representation another process can rebuild. It is needed since a heap object (e.g. a C struct, a Python dict) is a web of pointers, each a virtual address only its process’s page tables translate (§603#3.2), laid out as its language and compiler chose. No other host holds the mapping, nor does the channel carry a heap but only flat bytes. Therefore, a text format flattens in two steps, ($\Rightarrow$) the sender serialising the object to text, structure and values, $\to$ encoding that text as 8-bit unicode transformation format (UTF-8) bytes, ($\Leftarrow$) the receiver decoding $\to$ deserialising, whereas a binary format serialises each field to bytes directly, no text between. This representation, not delivery, is what OSI’s presentation layer ($\text{L}6$) names, a function TCP/IP folds into the application and its libraries.

The formats atop it trade legibility for density. Text formats such as JavaScript object notation (JSON) and extensible markup language (XML) stay human-readable and self-describing but verbose and slow to parse. YAML, designed as a JSON superset (1.2), earns the config and spec role by comments and concise syntax, and loses the wire to its richer type system, heavier parser, and unsafe deserialisation. Binary formats such as protobuf are denser and faster yet opaque. A format may further carry a schema, one definition both ends hold and validate against. The trade is flexibility for machine-checked agreement, since a breaking message fails at the boundary, where schemaless ends would misread it.

Note that the format fixes not just how bytes read, but also how they may change - the harder half once clients are live. They must stay backward-compatible (i.e. an old client understood by a new server) and forward-compatible (i.e. a new client tolerated by an old server), both kept by additive schema evolution, where an old field is never removed or repurposed. Only when a change cannot stay compatible is the API versioned, by URL (e.g. /v2/), header, or media type. For instance, Stripe pins a version per account and threads old requests via compatibility shims, thus one code-base serves a decade of clients. Google’s AIP also forbids breaking change within a major version.

Beyond format lies style, the axis to which the remaining sections turn. Styles are graded by coupling, the prior agreement the two ends must share before they interact. Who the ends are decides how much agreement is affordable, since an unknown public client the server cannot redeploy forces the loosest contract while two co-deployed services afford the tightest. The grading does not track the calendar, with the tight procedure contracts of RPC and the simple object access protocol (SOAP) coming first, REST loosening to inherit the web, and GraphQL and gRPC drawing the contract back as relationships narrowed. Each style is the contract its relationship makes possible.

4.2. REST

Roy Fielding, a co-author of HTTP/1.0 alongside Berners-Lee, shaped both HTTP/1.1 and the uniform resource identifier (URI) syntax (e.g. scheme://host/path?query). There he observed that the web, where one HTTP request hands a document to a browser or data to a program, already behaves as an API. His 2000 dissertation distilled the observation into a model named representational state transfer (REST). Machinery built for documents extends unchanged to any resource a program names and serves an order or a user as readily as a page, yet the two ends share nothing bespoke beyond HTTP’s generic contract and couple as loosely as the web itself.

At the outset, a relatively minimal contract seemed an improbable victor over richer rivals, even so it won with the web’s grain where the rivals cut against it. SOAP and XML-RPC (1998) rode HTTP as a pipe and buried each call in an opaque XML POST no intermediary can read. REST instead named the target in the URL and the effect in the verb, hence any cache or proxy could serve a repeat by method and URL alone. The same divide told in the formats. Browser-native JSON proved lighter than XML, whose markup heft descends from the standard generalised markup language (SGML) roots shared with HTML. REST rode the winner while SOAP kept its envelopes.

Practically, the contract reduces to a brief vocabulary. Anything nameable is a resource identified by a URI such that the server returns only a representation of its state. A client acts on the HTTP verbs, {create: POST, read: GET, update: PUT, delete: DELETE}. The verbs differ in guarantee. For instance, one has {GET} ⊂ {GET, PUT, DELETE}, as safety (i.e. state unchanged) implies idempotence (i.e. twice equals once, $f(f(x)) = f(x)$). Unlike a safe verb whose repeat changes nothing, POST holds neither and its repeat duplicates unless an idempotency key collapses it onto the first. The wire carries no schema and OpenAPI (i.e. Swagger UI) recovers one out of band for docs.

A resource need not be singular. A collection gathers many under one URI (e.g. GET /orders returns a list), thus it is unbounded, and the server leverages pagination such that each reply carries one page whose edge is fixed by position or value. An offset simply counts rows to skip. The database re-scans the skipped prefix at $O(N)$ for every page. An offset also names no row, so concurrent writes shift every later row and records repeat or vanish. A cursor instead fixes the edge by the last-seen value of the sort key and resumes past it through an index at $O(\log N)$, immune to that drift at the cost of forbidding jumps to an arbitrary page and demanding a unique ordering.

In summary, his dissertation grounds REST in six constraints chosen to induce scalability and generality, i) client-server separation, ii) statelessness, iii) cacheability, iv) a uniform interface, v) layering, and vi) optional code-on-demand. While statelessness contributes the most, letting any server answer any request and capacity scale horizontally, the strictest is the uniform interface whose hardest clause hypermedia as the engine of application state (HATEOAS) drives the client by server-returned links rather than URLs fixed in advance. The open web is therefore the purest REST, while most JSON services hardcode endpoints, a decay Fielding decried in 2008.

4.3. GraphQL

A fixed REST endpoint over-fetches a whole resource for one field, or under-fetches into several round-trips. GraphQL (Facebook 2012, open-sourced 2015) answers both by moving the shape of the response from server to client. A single typed schema, the first agreement REST did without and affordable since the vendor owned both ends, describes the graph of available fields. One endpoint accepts a query naming exactly the fields wanted across related entities, returning them in one round-trip. Each field is answered by its resolver, the server-side function fetching it from its table or service, thus the join runs inside the server rather than across the client’s round-trips.

The gain costs the leverage REST drew from HTTP. A lone POST endpoint defeats per-URL caching, and a query nesting to depth $d$ over branching factor $b$ fans out to $O(b^d)$ resolver calls, the $N+1$ problem its routine instance. Practice pays these down. Dataloader batching collapses the $N+1$ to $1+1$ by coalescing the keys requested within a tick into one query. Persisted queries (a hash standing in for the query text) restore GET caching, while depth and complexity ceilings bound a query’s cost. The query is also only one of the schema’s three root operations, mutations writing and subscriptions streaming server-pushed updates over a held connection.

GraphQL also rarely fronts one service, its schema an aggregation layer. Federation composes subgraphs, each owned by a separate backend, into one supergraph the gateway resolves, every field dispatched to its owning REST, gRPC, or datastore and reassembled into the requested shape. GitHub’s v4 API and Shopify expose their platforms through a single such graph. GraphQL thus stands as a backend-for-frontend before a microservice fleet rather than between its members, the gap the tightest style fills.

4.4. RPC

REST addresses a resource and hands back a snapshot of its state, whereas RPC names a procedure for the server to run, a noun answered by state against a verb answered by a computation. Between co-deployed services REST and GraphQL’s public-edge generality is dead weight, text over HTTP paying for reach no internal caller needs. Remote procedure call (RPC, Birrell and Nelson, 1984) tightens here.

The tightening rests on the stub, a local proxy generated from an interface definition both ends compile in advance, through which the client invokes the procedure. The stub marshals the arguments and unmarshals the reply, and the call thus reads as local, an abstraction leaking where the network fails or stalls as a local call would not.

Birrell and Nelson fixed both halves of what the stub hides. Binding resolves a name to a server before the first call, as an exporter registers its interface with a name service (Grapevine) and the importer fetches its address and a unique instance identifier, so a restarted server invalidates every stale binding. The call semantics are at-most-once, where a call that returns ran exactly once, a crashed or unreachable server raises an exception rather than a blind retry, and a live server that merely computes long is never timed out, so a hang reads as computation.

Tunnelled through HTTP by SOAP and XML-RPC, RPC lost to REST at the edge but returns on its own protocol, its implementations spread across coupling. JSON-RPC 2.0 (2010) sits at the loose end, a schemaless, transport-agnostic object of method, params, and id. gRPC (Google, 2015), its internal Stubby opened up, holds the tight end, typed protocol buffers (protobuf) over HTTP/2, whose multiplexing carries unary or streaming calls, fast but cache-opaque and unreachable from a browser without a grpc-web proxy, a fit for intra-cluster links and ML serving.

The language server protocol (LSP, Microsoft, 2016) first built on JSON-RPC at scale. $M$ editors wired to $N$ languages by hand form an $M \times N$ tangle of bespoke plugins, which LSP collapses to $M+N$ by the same hub factorisation as LLVM’s IR (§602#2.1), one JSON-RPC contract each language implements once for every editor and each editor once for every language. The insight was that language intelligence is a service, not an editor feature. A language server, a separate process speaking the protocol over stdio or a socket, answers completion, diagnostics, and go-to-definition, while the editor stays ignorant of the language’s toolchain, a template a new $M \times N$ tangle would soon borrow.

Anthropic’s model context protocol (MCP, 2024) applies the same $M+N$ collapse to LLM agents, built on the same JSON-RPC, one open standard a tool implements once for any client. A model’s reach is bounded by what it can call, and a shared protocol for tools and context is what turns a chatbot into an agent, its context window a bus any capability can plug into. A server exposes {resources: data, tools: typed functions, prompts: templates} over stdio or HTTP. Its transport evolved like HTTP’s, per-client HTTP+SSE giving way to a stateless Streamable HTTP (2025) endpoint any node can serve, echoing QUIC displacing TCP under HTTP/3.




I gathered words solely for my own purposes without any intention to break the rigour of the subjects.
I also prefer eating corn in spiral 🍴.

‹ Previous604. concurrency Next ›606. database
Ready