Part 03
Networking and API Design
Design a secure, versioned API and explain how a request crosses the network.
3.1 Network Foundations
Chapter outcomes and context
Topics covered: 23 OSI and TCP/IP models (Core) · 24 IP addressing and routing (Core) · 25 TCP and UDP (Core) · 26 DNS (Core)
Learning outcomes
- Use the TCP/IP layer model (link → internet → transport → application) as a reasoning and debugging map; know the OSI model as the reference vocabulary.
- Explain IP addressing, subnets, and how packets route between networks.
- Choose between TCP (connection-oriented, ordered, reliable, congestion-controlled) and UDP (connectionless, no delivery or ordering guarantees, lower latency): TCP for APIs and data; UDP for live media, DNS queries, and QUIC.
- Trace a DNS resolution (stub → recursive resolver → root → TLD → authoritative) and explain TTL caching. DNS is also a load-balancing and failover tool (→ 94).
Key concepts: packets, the TCP three-way handshake, flow and congestion control, ports, NAT, DNS record types (A/AAAA, CNAME, TXT).
3.2 TLS and HTTP
Chapter outcomes and context
Topics covered: 27 TLS and secure communication (Core) · 28 HTTP fundamentals: HTTP/1.1, HTTP/2 and HTTP/3 (Core)
Learning outcomes
- Explain what TLS provides — confidentiality, integrity, server authentication via certificates — and sketch the handshake and the role of certificate authorities.
- Use HTTP semantics correctly (RFC 9110): method guarantees (GET/HEAD safe;
GET/PUT/DELETE idempotent; POST neither), status code classes, headers, content
negotiation, HTTP caching (
Cache-Control,ETag). - Compare protocol versions: HTTP/1.1 (one request at a time per connection), HTTP/2 (multiplexed streams over one TCP connection; still TCP head-of-line blocking on packet loss), HTTP/3 (QUIC over UDP, RFC 9114 — removes transport head-of-line blocking, faster setup).
3.3 Proxies and the Request Path
Chapter outcomes and context
Topics covered: 29 Reverse proxy and forward proxy (Core) · 30 What happens when you type a URL (Core — ties Part 3 together)
Learning outcomes
- Distinguish a forward proxy (acts for clients: egress control, anonymity) from a reverse proxy (acts for servers: TLS termination, compression, routing, buffering).
- Narrate the canonical synthesis question end to end: URL parsing → DNS → TCP → TLS → HTTP request → proxy → server → response → render — naming every topic from Chapters 3.1–3.2 in its place.
3.4 API Styles and Serialization
Chapter outcomes and context
Topics covered: 31 REST API design (Core) · 32 GraphQL (Core) · 33 gRPC (Core) · 34 Serialization and schema evolution: JSON, Protocol Buffers, Avro, schema registries, compatibility rules (Advanced)
Learning outcomes
- Design a clean REST API: resources and URIs, correct verb and status usage, statelessness, consistent error bodies.
- Know when GraphQL fits (many client shapes over the same data, bandwidth-constrained clients, aggregation) and its costs (server complexity, caching difficulty, N+1 queries, query cost control).
- Know when gRPC fits (internal service-to-service calls, strong contracts, streaming, low latency) and what Protocol Buffers provide.
- (Advanced) Reason about serialization and schema evolution: JSON (self-describing, verbose) vs. Protobuf and Avro (compact, schema-driven); schema registries enforcing compatibility rules (backward, forward, full) — the foundation for safe event contracts (→ 113; applied in Project 19).
Decision rule: REST as the default public API; gRPC inside the backend; GraphQL only when the client-shape problem is real. The simpler alternative at small scale: one well-designed REST API.
3.5 API Contract Mechanics
Chapter outcomes and context
Topics covered: 35 API versioning and backward compatibility (Core) · 36 API contract-first design: OpenAPI, AsyncAPI, contract validation, deprecation (Core) · 37 Pagination, filtering and sorting (Core) · 38 Idempotency keys and safe API retries (Core)
Learning outcomes
- Version APIs safely: additive, backward-compatible change first; URI or header versioning when a break is unavoidable; a published deprecation policy.
- Work contract-first: the OpenAPI document (synchronous APIs) or AsyncAPI document (event and message contracts) is written and reviewed before the implementation; contracts are validated in CI against the implementation, and deprecation is part of the contract's lifecycle. Simpler alternative: code-first with generated specs — acceptable for one team, weak across teams.
- Design list endpoints: offset vs. cursor pagination (cursor is stable under inserts and cheap at depth), filtering, sorting, hard result limits.
- Design idempotency keys (primary home of API-level idempotency): the client sends a unique key with a mutating request; the server stores the key with the outcome and returns the stored outcome on retry — making "retry on timeout" safe for payments and orders (Project 8; consumer-side idempotency → 116).
3.6 API Access Basics
Chapter outcomes and context
Topics covered: 39 API authentication and authorization basics: API keys, sessions, tokens, resource-level checks (Core — full detail → 159–163)
Learning outcomes
- Protect an API from day one: API keys (identify a calling application), sessions (server-side state referenced by a cookie), tokens (self-contained credentials sent per request) — and where each fits.
- Enforce resource-level checks: not just "is this user logged in" but "may this user touch this object" — the missing check behind most real-world access-control bugs.
- Know the boundary: this topic equips Projects 1, 3 and 4 with safe-enough access control; identity lifecycle, OAuth/OIDC, JWT mechanics, and RBAC/ABAC in depth are topics 159–163.
3.7 Real-Time Communication
Chapter outcomes and context
Topics covered: 40 Real-time communication: polling, long polling, WebSockets, SSE, webhooks (Core)
Learning outcomes
- Compare the mechanisms and choose by need: short polling (simplest), long polling (server holds the request until data arrives), SSE (one-way server→client stream with auto-reconnect — feeds, notifications), WebSockets (full-duplex persistent connection — chat, games, collaboration), webhooks (server-to-server push; the receiver verifies signatures and tolerates duplicates and reordering — Project 8).
- Account for persistent-connection costs: memory per connection, load-balancer affinity, reconnect storms, scaling the connection tier (Project 12).
Simpler alternative: polling is correct more often than it is fashionable; upgrade only when the latency or efficiency requirement demands it.
3.8 Edge Infrastructure
Chapter outcomes and context
Topics covered: 41 API gateway (Core) · 42 Service discovery (Advanced)
Learning outcomes
- Explain what an API gateway (primary home) adds on top of a reverse proxy: authentication, rate limiting (→ 96), routing and aggregation, protocol translation, per-client policies — and its risks: a single point of failure and a magnet for business logic that belongs in services. Simpler alternative: a plain reverse proxy when there is one service and one client type.
- (Advanced) Explain service discovery: how services find each other in a dynamic environment — client-side vs. server-side discovery, health-checked registries (DNS-based, or systems such as Consul and etcd as examples → 136).
Done when you can
- Trace and time every network stage of a real HTTPS request.
- Write an API contract first, and choose REST vs. GraphQL vs. gRPC vs. WebSocket with reasons.
- Ship an API whose mutating endpoints are safely retryable and whose objects check access.