SystemExpertsSystemExperts
Pricing

Patterns

35 items

Horizontal Scaling Pattern

15mbeginner

Retry with Backoff Pattern

15mbeginner

Replication Pattern

25mintermediate

Caching Strategies Pattern

25mintermediate

Persistent Connections Pattern

20mintermediate

Load Balancing Pattern

20mintermediate

Fan-out Pattern

20mintermediate

Fan-in Pattern

20mintermediate

Circuit Breaker Pattern

20mintermediate

Eventual Consistency Pattern

25mintermediate

Queue-based Load Leveling Pattern

20mintermediate

Bloom Filters Pattern

20mintermediate

Time-Series Storage Pattern

20mintermediate

Bulkhead Pattern

20mintermediate

Batch Processing Pattern

20mintermediate

Write-Ahead Log Pattern

20mintermediate

API Gateway Pattern

20mintermediate

Backend for Frontend Pattern

20mintermediate

Sidecar Pattern

20mintermediate

Idempotency Pattern

20mintermediate

Rate Limiting Pattern

20mintermediate

Backpressure Pattern

20mintermediate

Pub/Sub Pattern

25mintermediate

Strong Consistency Pattern

30madvanced

Conflict Resolution Pattern

25madvanced

Leader Election Pattern

25madvanced

Consensus Protocols Pattern

30madvanced

CQRS Pattern

28madvanced

LSM Trees Pattern

25madvanced

Sharding Pattern

25madvanced

Event Sourcing Pattern

30madvanced

Stream Processing Pattern

25madvanced

Change Data Capture Pattern

25madvanced

Distributed Locking Pattern

25madvanced

Two-Phase Commit Pattern

25madvanced
System Design Pattern
Communicationwebsocketsselong-pollingreal-timebidirectionalintermediate

Persistent Connections Pattern

Long-lived connections for real-time communication

Used in: Chat Applications, Live Updates, Gaming|20 min read

Summary

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.

Key Takeaways

Connection Establishment Overhead

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.

Resource Management Trade-off

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.

Multiplexing Enables Efficiency

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!

Connection Per Request vs Persistent

Summary

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.

Key Takeaways

Connection Establishment Overhead

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.

Resource Management Trade-off

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.

Multiplexing Enables Efficiency

HTTP/2 and gRPC multiplex multiple requests over single connection. No head-of-line blocking. Single connection handles hundreds of concurrent requests efficiently.

Enables Server Push

Persistent connections enable bidirectional communication. Server can push updates without client polling. Essential for real-time features like chat, notifications, live updates.

Premium Content

Sign in to access this content or upgrade for full access.

Connection Pooling

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 Connection Management

Idle connections waste resources. Implement timeouts to close unused connections. Balance between keeping connections warm and freeing resources.

Pattern Details

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!

Connection Per Request vs Persistent

Trade-offs

AspectAdvantageDisadvantage