Network latency is the total time for data to travel from source to destination. It consists of several components, each contributing to overall delay.
Latency Components:
- Propagation Delay: Time for signal to travel physical distance
- Formula: Distance / Propagation Speed
- Speed of light in fiber: ~200,000 km/s (2/3 of c)
- Speed of light in vacuum: ~300,000 km/s
- Example: 1000 km fiber = 1000/200000 = 5ms one-way
- Transmission Delay: Time to push all bits onto the link
- Formula: Packet Size / Link Bandwidth
- Example: 1500 bytes / 1 Gbps = 0.012 ms (negligible)
- More significant on slower links (dial-up, satellite)
- Processing Delay: Time routers/switches take to process packet
- Includes: header inspection, routing table lookup, error checking
- Typical range: 0.1-10 ms per hop
- Modern routers: <1 ms, legacy equipment: 5-10 ms
- Queuing Delay: Time packet waits in buffers before transmission
- Most variable component (depends on congestion)
- Can range from 0 ms (no congestion) to 100+ ms (heavy congestion)
- Causes "jitter" in latency measurements
Round-Trip Time (RTT):
- Definition: Time for packet to reach destination and return
- Formula: RTT = 2 × One-Way Latency (for symmetric paths)
- Measurement: Commonly measured using ping (ICMP Echo Request/Reply)
- Asymmetry: In reality, forward and reverse paths may differ
Speed of Light Limitations:
- Vacuum: 299,792 km/s (theoretical maximum)
- Fiber Optic Cable: ~200,000 km/s (~67% of light speed)
- Refractive index of glass slows light
- Typical refractive index: 1.47
- Copper Cable: ~200,000 km/s (similar to fiber)
- Electrical signal propagation in copper
- Physical Limits: Cannot be circumvented, only minimized
- New York to London: ~5,570 km
- Minimum RTT: 2 × 5570/200000 = 55.7 ms (fiber)
- Realistic RTT: 70-100 ms (with routing/processing)
Real-World Latency Examples:
- LAN (same building): <1 ms
- Same city: 1-5 ms
- Within region (e.g., US West Coast): 10-30 ms
- Cross-country (NY to LA): 60-80 ms
- Transatlantic (US to Europe): 80-120 ms
- US to Asia: 150-250 ms
- Satellite (geostationary): 500-700 ms
- LEO satellite (Starlink): 20-40 ms
Application Latency Requirements:
- Real-time Gaming: <20 ms (competitive), <50 ms (acceptable)
- VoIP (Voice Calls): <150 ms (ITU-T G.114 recommendation)
- Video Conferencing: <200 ms (acceptable), <100 ms (good)
- Web Browsing: <200 ms (first byte), <1000 ms (page load)
- Financial Trading: <1 ms (HFT), every microsecond matters
- Remote Desktop: <50 ms (responsive), <100 ms (usable)
- Video Streaming: Latency less critical (buffering handles it)
Ping vs Application Latency:
- Ping (ICMP): Measures network latency only
- Application Latency: Includes server processing time
- Formula: Network RTT + Server Processing + Application Logic
- Example: 50ms RTT + 100ms server time = 150ms app latency
- TCP Handshake: Adds 1 RTT before data transfer
- TLS Handshake: Adds 1-2 RTT for HTTPS connections
Latency Optimization Strategies:
- Geographic Distribution:
- Deploy CDN edge servers close to users
- Multi-region cloud deployments
- Anycast routing to nearest server
- Protocol Optimization:
- HTTP/2 multiplexing (reduce RTT impact)
- HTTP/3 (QUIC) with 0-RTT resumption
- TCP Fast Open (save 1 RTT)
- Connection pooling and keep-alive
- Caching:
- Browser caching (eliminate network round-trip)
- CDN caching at edge
- Application-level caching (Redis, Memcached)
- Network Path Optimization:
- Peering agreements to reduce hops
- Direct fiber connections between data centers
- BGP route optimization
Measuring Latency:
- ping: ICMP echo request/reply
ping google.com
# Output: 64 bytes from 172.217.14.206: time=15.2 ms
- traceroute/tracert: Show latency per hop
traceroute google.com
# Shows latency to each router along the path
- curl: Measure HTTP request time
curl -w "@curl-format.txt" -o /dev/null -s https://example.com
# time_namelookup, time_connect, time_starttransfer, time_total
- Browser DevTools: Network tab shows timing breakdown
Jitter:
- Definition: Variation in latency over time
- Causes: Variable queuing delays, route changes, network congestion
- Impact: Critical for real-time applications (VoIP, gaming)
- Mitigation: QoS (Quality of Service), traffic prioritization, jitter buffers
Latency vs Bandwidth:
- Latency: Time for first bit to arrive (delay)
- Bandwidth: Amount of data per second (throughput)
- Analogy: Latency = travel time, Bandwidth = highway width
- High bandwidth does NOT fix high latency
- Example: 1 Gbps satellite link still has 600ms latency
Financial Trading Example:
- High-Frequency Trading (HFT) requires <1 ms latency
- Firms collocate servers in exchange data centers
- Direct fiber connections between exchanges
- Microwave links faster than fiber for long distances (line-of-sight)
- Example: Chicago to New York via microwave = 8.5 ms vs fiber = 13 ms
Best Practices:
- Measure latency from user locations, not just data center
- Monitor latency continuously (not just during testing)
- Set realistic latency SLAs based on physics
- Use percentiles (p50, p95, p99) not just averages
- Deploy globally for latency-sensitive applications
- Consider edge computing for processing closer to users