1. Implementing Database Indexing
| Index Type | Use |
| B-tree | Equality, range, sort (default) |
| Hash | Equality only (in-memory) |
| GIN / GiST | JSON, full-text, arrays |
| Composite | Multi-column queries (order matters) |
| Covering | Include needed columns; index-only scan |
| Partial | Index subset (e.g. WHERE active=true) |
2. Using Connection Pooling
| Library | Language |
| HikariCP | Java |
| pgbouncer | PostgreSQL (external) |
| node-postgres pool | Node.js |
| SQLAlchemy pool | Python |
| Setting | Recommendation |
| Pool size | ≈ (CPU cores × 2) + disk count |
| Connection timeout | 30s |
| Idle timeout | 10 min |
| Max lifetime | 30 min (rotate connections) |
3. Using CDN for Static Resources
| CDN | Strength |
| Cloudflare | Free tier, edge functions |
| Fastly | VCL, real-time purge |
| CloudFront | AWS integration |
| Akamai | Enterprise scale |
4. Implementing API Response Caching
| Layer | Tool |
| HTTP edge | CDN with Cache-Control |
| Application | Redis, Memcached |
| In-process | Caffeine (Java), LRU-cache (Node) |
| Database | Materialized views, query cache |
5. Using Lazy Loading
| Pattern | Trade-off |
| Lazy | On-demand fetch; risk of N+1 |
| Eager | Load upfront; over-fetching |
| Explicit (DataLoader) | Batch + cache lazy fetches |
6. Implementing Field Selection
See section 15. Reduces payload size and DB I/O by returning only requested columns.
| Effect | Benefit |
| Smaller payloads | Less bandwidth, faster parse |
| Index-only scans | No table heap access |
| Skip JOINs | Faster query plans |
7. Using Asynchronous Processing
| Pattern | Use Case |
| Message queue (Kafka, RabbitMQ, SQS) | Decouple slow work from request |
| Background workers | Email send, image resize, reports |
| Event-driven | Pub/sub for cross-service work |
| 202 Accepted + polling | Long-running operations (section 27) |
8. Implementing Database Query Optimization
| Technique | Benefit |
EXPLAIN ANALYZE | Identify slow queries |
Avoid SELECT * | Project only needed columns |
Use LIMIT + index | Avoid full scans |
| Batch queries | Reduce round-trips (IN clause) |
| Read replicas | Offload SELECTs from primary |
| Materialized views | Precomputed aggregates |
| Sharding / partitioning | Horizontal scale |
| Metric | Threshold |
| p50 latency | < 100ms |
| p95 latency | < 500ms |
| p99 latency | < 1s |
| Error rate | < 0.1% |
| Throughput (req/s) | Track per endpoint |
| Saturation (CPU, memory, DB) | < 70% sustained |
10. Implementing Load Balancing
| Algorithm | Use |
| Round-robin | Simple, equal capacity |
| Least connections | Long-lived connections |
| Weighted | Heterogeneous instance sizes |
| IP/session hash | Sticky sessions (avoid if stateless) |
| Geographic | Latency-based routing |
11. Using HTTP/2
| Feature | Benefit |
| Multiplexing | Concurrent streams on one connection |
| Header compression (HPACK) | Reduce overhead |
| Server push DEPRECATED | Removed in Chrome 106; use early hints (103) |
| Binary framing | More efficient parsing |
12. Implementing Connection Keep-Alive
| Header | Value |
Connection: keep-alive | HTTP/1.1 default |
Keep-Alive: timeout=30, max=100 | 30s idle, 100 reqs per connection |
| HTTP/2 | Always persistent |