$ ss -tulnp && openssl s_client -tls1_3 -connect host:443
Networking, Transport & Data Formats
// from struct in memory to packets on the wire
End-to-end wire path
// tcp vs udp vs quic (http/1.1 → http/3)
Transport Protocols
| Property | TCP | UDP | QUIC (UDP + TLS 1.3) |
|---|---|---|---|
| Handshake RTT | 1 RTT (SYN / SYN-ACK / ACK); +1 RTT for TLS 1.3 = 2 RTT | 0 RTT (connectionless) | 1 RTT cold (transport + TLS 1.3 merged); 0-RTT resumed (replayable!) |
| Ordering & HoL Blocking | Strict byte-stream order; 1 lost packet stalls ALL multiplexed HTTP/2 streams | Unordered datagrams; app handles loss/order | Independent streams inside 1 connection; loss stalls only the affected stream |
| Encryption & Ossification | Headers plaintext → middleboxes inspect/drop new TCP options | Plaintext unless wrapped (DTLS / WireGuard) | Transport headers + ACKs encrypted; middleboxes see only UDP + short header |
| Connection Migration | Tied to 4-tuple (srcIP, srcPort, dstIP, dstPort) → Wi-Fi→5G drops connection | Stateless | Identified by Connection ID → survives IP/NAT rebinding without reconnect |
| HTTP Mapping | HTTP/1.1 (1 req/conn or pipelining) & HTTP/2 (binary frames, HPACK, TCP HoL) | DNS, VoIP, gaming, WireGuard | HTTP/3 (QPACK header compression, no transport HoL) |
// asymmetric key agreement → symmetric aead
Public Key Encryption & TLS 1.3
| Mechanism | How it works | Security Consequence |
|---|---|---|
| Hybrid Encryption | Asymmetric crypto (X25519 / RSA / ECDSA) is ~1000× slower than symmetric | TLS uses asymmetric crypto ONLY for key agreement + server AuthN, then switches to AEAD (AES-256-GCM or ChaCha20-Poly1305) via HKDF |
| Forward Secrecy (ECDHE) | Ephemeral Diffie-Hellman keys per session, discarded after handshake | TLS 1.3 removed static RSA key exchange: stealing the server's private key later cannot decrypt previously recorded traffic |
| 0-RTT Early Data | Client sends app data in first flight using PSK from a prior session | NOT replay-safe across servers: only allow idempotent GET requests, never state-changing operations |
| PKI & Revocation | Server presents X.509 cert chain signed by a trusted Root CA | Validate hostname (SAN) + chain + expiry; Certificate Transparency (CT) detects rogue CAs; OCSP stapling avoids client-side revocation lookup leaks |
| mTLS (Mutual TLS) | Server ALSO requests and verifies the client's X.509 certificate | Core building block of Zero Trust service meshes (SPIFFE/SPIRE): authenticates both endpoints at L4/L5 before L7 runs |
// l2 switches, openwrt routers, bgp & l4/l7 proxies
Network Components
| Component | Layer | What it inspects / rewrites | Hard Detail |
|---|---|---|---|
| L2 Switch | L2 (Frames) | Forwards by MAC address table + 802.1Q VLAN isolation | Does not route across IP subnets; broadcast domain boundary is L3 |
| Router / OpenWrt | L3 (Packets) | Routes IP prefixes (OSPF/BGP), runs NAT/masquerade, stateful nftables firewall, DHCP/DNS | OpenWrt brings Linux netifd, VLANs, WireGuard & SQM/CAKE (anti-bufferbloat) to embedded routers; VyOS/FRR/OPNsense cover DC/edge routing |
| NAT / Stateful Firewall | L3–L4 | Rewrites src/dst IP:port via conntrack table; drops unsolicited inbound packets | NAT is address sharing, NOT a security architecture; symmetric NAT breaks P2P/UDP hole punching |
| L4 Load Balancer | L4 (TCP/UDP) | Distributes connections by 5-tuple hash; supports DSR (Direct Server Return) & TLS passthrough | Very high throughput, low latency, but blind to HTTP paths/headers/cookies |
| L7 Reverse Proxy / WAF | L7 (HTTP/gRPC) | Terminates TLS, routes by host/path, enforces rate limits, AuthN/AuthZ, header hygiene (Envoy, Nginx) | Sees plaintext payload; must preserve X-Forwarded-For safely (strip untrusted client headers!) |
| API / LLM Router | L7 (App) | Routes model/API calls across providers with fallback, quota, token accounting (e.g. OpenRouter, Envoy AI Gateway) | Adds unified auth/billing and failover, but introduces an extra trust hop for sensitive prompts |
| VPN (WireGuard / IPsec) | L3 Tunnel | Encapsulates IP packets in authenticated encrypted UDP (Noise_IK in WireGuard) | WireGuard is stateless-looking (silent drop on bad MAC, ~4k LoC, kernel-space); still needs Zero Trust L7 AuthZ inside |
// deployment models × functional roles
Types of Servers
| Functional Type | State | Role | Primary Bottleneck / Failure Mode |
|---|---|---|---|
| Web / Edge / CDN | Stateless | TLS termination, static assets, HTTP/3 edge caching | Network bandwidth / TLS handshakes |
| Application / API | Stateless (ideally) | Business logic, AuthZ, orchestration; scales horizontally behind LB | CPU, GC pauses, downstream DB/RPC latency |
| Database (OLTP / OLAP) | Stateful | ACID transactions & durability (Postgres) or columnar analytics (ClickHouse) | Disk IOPS, write locks, replication lag |
| Cache (Redis / Memcached) | Ephemeral state | Sub-ms RAM key-value reads, rate-limit counters, session stores | Memory eviction, cache stampede (thundering herd) |
| Message Broker (Kafka / NATS) | Durable log / queue | Decouples producers/consumers, absorbs traffic spikes, replayable event streams | Consumer lag, partition skew, poison-pill messages |
// json vs cbor vs protobuf vs flatbuffers
Data-Serialization Formats
| Format | Wire | Schema | 0-Copy | Strength | Hard Gotcha |
|---|---|---|---|---|---|
| JSON | Text | No | No | Universal, human-readable, self-describing | No binary type (Base64 +33%), IEEE-754 loses precision > 2^53, repeats keys on every object |
| CBOR (RFC 8949) | Binary | No | No | Compact JSON superset + native bytes/tags; deterministic CBOR (CDE) supports canonical crypto signing (COSE, WebAuthn) | Smaller ecosystem than JSON; still carries field keys unless integer keys are used |
| MessagePack | Binary | No | No | Drop-in binary JSON, very compact for small payloads | No standard canonical form; less typed than CBOR tags |
| Protobuf | Binary | Yes (.proto) | No | Numeric field tags + varint encoding; strong forward/backward evolution; default for gRPC | Not canonical (field order & unknown fields vary → never sign raw Protobuf bytes directly) |
| Apache Avro | Binary | Yes (JSON schema) | No | No per-field tags on wire (smallest for bulk records); schema registry handles reader/writer evolution | Reader MUST have exact writer schema to decode; poor fit for ad-hoc RPC |
| FlatBuffers / Cap'n Proto | Binary | Yes (IDL) | Yes | Zero-copy random access directly from mmap/packet buffer via vtable offsets (no parse/alloc step) | Larger wire size than Protobuf (alignment padding + offsets); stricter schema evolution |