Patterns
35 items
35 items
Long-lived connections for real-time communication
Persistent connections maintain long-lived TCP connections between clients and servers instead of opening a new connection for each request. This eliminates the overhead of TCP handshake, TLS negotiation, and connection establishment for every request. HTTP/2, WebSockets, gRPC, and database connection pools all use persistent connections. The pattern reduces latency by 100-300ms per request, decreases server load from connection churn, and enables server-push capabilities like real-time updates. However, it requires careful resource management since connections consume memory and file descriptors on both client and server.
Each new TCP connection requires 3-way handshake (1.5 RTT). With TLS, add 1-2 more round trips for key exchange. Persistent connections pay this cost once, not per request.
Each connection consumes memory (~10KB) and a file descriptor. 100K concurrent connections = 1GB RAM and file descriptor limits. Must balance connection count vs resource usage.
HTTP/2 and gRPC multiplex multiple requests over single connection. No head-of-line blocking. Single connection handles hundreds of concurrent requests efficiently.
Cost of establishing a new connection:
TCP Handshake: 1.5 round trips - SYN → SYN-ACK → ACK - ~30-100ms depending on latency
TLS Handshake: 1-2 additional round trips - ClientHello → ServerHello + Certificate - Key exchange → Finished - ~50-200ms additional
Total: 80-300ms just to establish connection before any data transfer!
HTTP/1.0 Pattern (No persistence): Every request: 1. Open connection (80-300ms) 2. Send request 3. Receive response 4. Close connection
For 10 resources on a page: 10 × 300ms = 3 seconds of connection overhead alone!
Database connections are expensive (authentication, session setup). Connection pools maintain warm connections and reuse them across requests. Reduces connection overhead from seconds to milliseconds.
Idle connections waste resources. Implement timeouts to close unused connections. Balance between keeping connections warm and freeing resources.
Cost of establishing a new connection:
TCP Handshake: 1.5 round trips - SYN → SYN-ACK → ACK - ~30-100ms depending on latency
TLS Handshake: 1-2 additional round trips - ClientHello → ServerHello + Certificate - Key exchange → Finished - ~50-200ms additional
Total: 80-300ms just to establish connection before any data transfer!
HTTP/1.0 Pattern (No persistence): Every request: 1. Open connection (80-300ms) 2. Send request 3. Receive response 4. Close connection
For 10 resources on a page: 10 × 300ms = 3 seconds of connection overhead alone!
| Aspect | Advantage | Disadvantage |
|---|---|---|