Networking Architectures, Transport Protocols & API Design
Network protocols dictate how bytes stream across physical sockets, manage packet loss recovery, compress headers, and handle binary vs textual serialization.
1. The OSI 7-Layer Model & Real-World TCP/IP Stack
HTTP, gRPC
TLS, Protobuf
Sockets
TCP, UDP
IP, BGP
Ethernet, MAC
Fiber, Copper
2. TCP vs UDP & Handshake Mechanics
Connection-oriented, reliable in-order byte stream delivery. Uses 3-Way Handshake (SYN \(\rightarrow\) SYN-ACK \(\rightarrow\) ACK) and Sliding Window Congestion Control (TCP Slow Start, Reno/CUBIC).
Cost: Minimum 1 RTT before any application data can be sent.Connectionless, unreliable datagram protocol. Zero handshake overhead, zero head-of-line blocking, zero flow control. Ideal for real-time video streaming, gaming, and HTTP/3 QUIC.
Cost: Application layer must handle packet loss if reliability is required.3. HTTP Evolution: HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
4. API Architecture Paradigms: REST vs GraphQL vs gRPC
| Feature | REST | GraphQL | gRPC |
|---|---|---|---|
| Protocol | HTTP/1.1 or HTTP/2 | HTTP/1.1 or HTTP/2 | HTTP/2 (Multiplexed) |
| Payload Format | JSON / XML | JSON | Protocol Buffers (Binary) |
| Schema Contracting | Optional (OpenAPI/Swagger) | Strict GraphQL Schema | Strict `.proto` Definition |
| Over-Fetching | Common | Eliminated (Client Queries) | Eliminated |
| Streaming Support | Limited (SSE/WS) | Subscriptions (WS) | Native Bi-directional Streaming |
5. Distributed Rate Limiting Algorithms
Bucket holds max \(B\) tokens. Refill rate \(R\) tokens/sec. Request consumes 1 token. Handles bursty traffic well.
tokens = min(capacity, tokens + (now - lastRefill) * refillRate);
if (tokens >= 1) { tokens--; allow(); } else { deny(); }
Combines past window count and current window count using weighted interpolation to prevent burst spikes at boundary borders.