Designing Network Performance Optimization
1. Designing Connection Pooling
| Aspect | Detail |
|---|---|
| Reuse TCP / TLS | Avoid handshake per call |
| Pool size | Per backend; tune to throughput |
| Idle timeout | Match server keepalive |
| DB pool | HikariCP, pgbouncer |
| HTTP client | Reuse single client (Java HttpClient, OkHttp) |
2. Designing DNS Resolution and Caching
| Practice | Detail |
|---|---|
| Local resolver | NodeLocal DNSCache (K8s) |
| JVM TTL | networkaddress.cache.ttl=60 |
| DoH / DoT | Encrypted DNS |
| Don't over-cache | Breaks failover |
3. Designing TCP Optimization
| Tuning | Detail |
|---|---|
| Window scaling | For high BDP |
| TCP_NODELAY | Disable Nagle for latency |
| Keepalive | Detect dead peers |
| BBR | Modern congestion control |
| SO_REUSEPORT | Multi-process accept |
4. Designing HTTP Pipelining and Multiplexing
| Protocol | Detail |
|---|---|
| HTTP/1.1 pipelining | Effectively dead |
| HTTP/2 | Multiplexed streams |
| HTTP/3 (QUIC) | UDP; no head-of-line blocking |
| gRPC | HTTP/2 native |
5. Designing Request Batching
| Pattern | Detail |
|---|---|
| Batch endpoints | POST /items/batch |
| DataLoader | Coalesce within tick (GraphQL) |
| Micro-batching | Buffer N ms, flush together |
| Caveat | Latency vs throughput trade-off |
6. Designing Latency Optimization
| Lever | Detail |
|---|---|
| Edge presence | CDN / edge compute |
| Co-locate | App near DB / cache |
| Parallel calls | Fan-out concurrent vs serial |
| Hedged requests | Send to 2 replicas; first wins |
| Reduce hops | Combine services for hot paths |
7. Designing Connection Reuse Patterns
| Practice | Detail |
|---|---|
| HTTP keep-alive | Reuse TCP for multiple requests |
| Persistent gRPC channel | One channel per backend |
| DB persistent conn | Pgbouncer transaction-mode |
| Avoid creating client per call | Common bug |
8. Designing Payload Size Optimization
| Technique | Detail |
|---|---|
| Compression | gzip / brotli / zstd |
| Sparse fields / projection | Return only needed |
| Pagination | Avoid mega responses |
| Avoid base64 large blobs | Use signed URLs |
| Trim metadata | Don't send debug data |
9. Designing Protocol Buffers and Binary Serialization
| Format | Detail |
|---|---|
| Protobuf | Schema-driven, compact |
| Avro | Schema registry; data pipelines |
| MessagePack / CBOR | Schemaless binary |
| FlatBuffers / Cap'n Proto | Zero-copy |
| Trade-off | Binary perf vs JSON debuggability |
10. Designing Network Timeout Strategy
| Layer | Detail |
|---|---|
| Connect timeout | Short (~1s) |
| Request timeout | Bound by SLO |
| Deadline propagation | Pass remaining budget |
| Cap retries × timeout | Avoid amplification |
11. Designing Edge Computing Architecture
| Platform | Detail |
|---|---|
| Cloudflare Workers | V8 isolates; ms cold start |
| Lambda@Edge / CloudFront Functions | AWS |
| Fastly Compute@Edge | WASM |
| Use cases | Auth, A/B, personalization, geo, image transform |
| Constraints | Limited CPU/mem; no long-running |
12. Designing Content Compression
| Algorithm | Detail |
|---|---|
| gzip | Universal |
| brotli | ~20% better; precompute static |
| zstd | Streaming, fast |
| Negotiation | Accept-Encoding header |
| Don't compress | Already-compressed media |