{
    "slug": "network_latency_bandwidth",
    "term": "Latency vs Bandwidth",
    "category": "networking",
    "difficulty": "intermediate",
    "short": "Latency is delay per request (physics + processing); bandwidth is throughput — high bandwidth does not fix high latency for small interactive responses.",
    "long": "Latency: time for a packet to travel from source to destination — physical distance, hops, processing time. Cannot be improved beyond the speed of light. Bandwidth: maximum data transfer rate — upgradeable with better hardware. For small responses (API calls, HTML pages), latency dominates performance. A 10Mbps connection at 10ms RTT delivers a 10KB response faster than 100Mbps at 200ms RTT. HTTP/2 multiplexing and CDN reduce the impact of latency.",
    "aliases": [
        "latency",
        "bandwidth",
        "RTT",
        "round trip time",
        "throughput"
    ],
    "tags": [
        "networking",
        "performance"
    ],
    "misconception": "More bandwidth always means a faster website — for small responses latency dominates; a 100Mbps connection with 200ms latency downloads a 10KB response in 200ms while a 10Mbps at 10ms delivers it in 10ms.",
    "why_it_matters": "Optimising image sizes (bandwidth) on an API making 20 serial requests (latency bottleneck) delivers minimal improvement — identifying the correct constraint guides correct optimisation.",
    "common_mistakes": [
        "Serial HTTP requests where parallel would reduce total time",
        "No HTTP keep-alive — each new connection adds one RTT",
        "No CDN — distant users have high latency regardless of origin bandwidth",
        "Optimising file sizes when connection count is the real bottleneck"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "http_request_response_cycle",
        "http3_quic",
        "cdn",
        "prefetching_strategies"
    ],
    "prerequisites": [
        "tcp_ip_model",
        "http_caching",
        "cdn"
    ],
    "refs": [
        "https://hpbn.co/"
    ],
    "bad_code": "// 10 serial API calls — each adds full RTT:\nasync function loadDashboard() {\n    const user    = await fetch('/api/user');     // 100ms RTT\n    const orders  = await fetch('/api/orders');   // 100ms RTT\n    const reviews = await fetch('/api/reviews');  // 100ms RTT\n    // Total: 300ms in latency alone\n}",
    "good_code": "// Parallel requests — latency is max(individual):\nasync function loadDashboard() {\n    const [user, orders, reviews] = await Promise.all([\n        fetch('/api/user'),\n        fetch('/api/orders'),\n        fetch('/api/reviews'),\n    ]);\n    // Total: ~100ms (parallel) vs 300ms (serial)\n}",
    "quick_fix": "Latency is round-trip time (affected by distance); bandwidth is throughput (affected by connection speed) — PHP apps suffer latency not bandwidth; reduce round trips with CDN, HTTP/2, and connection reuse",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/network_latency_bandwidth",
        "html_url": "https://codeclaritylab.com/glossary/network_latency_bandwidth",
        "json_url": "https://codeclaritylab.com/glossary/network_latency_bandwidth.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Latency vs Bandwidth](https://codeclaritylab.com/glossary/network_latency_bandwidth) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/network_latency_bandwidth"
            }
        }
    }
}