{
    "slug": "load_testing",
    "term": "Load Testing",
    "category": "testing",
    "difficulty": "intermediate",
    "short": "Testing system behaviour under expected and peak load conditions to identify performance bottlenecks and breaking points before they affect users.",
    "long": "Load testing generates concurrent requests to simulate production traffic levels. Types: load testing (expected peak), stress testing (find breaking point), soak testing (sustained load over hours), spike testing (sudden burst). Tools include k6 (JavaScript DSL), JMeter (Java GUI), and Locust (Python). Key metrics: requests per second, p95/p99 latency, error rate, and resource saturation. Results reveal N+1 queries, missing indexes, and connection pool exhaustion that unit tests cannot find.",
    "aliases": [
        "stress testing",
        "performance testing",
        "k6",
        "JMeter"
    ],
    "tags": [
        "testing",
        "performance",
        "devops"
    ],
    "misconception": "Load testing only matters for large applications — a single misconfigured query can make a small app fail under tens of concurrent users, not thousands.",
    "why_it_matters": "Performance problems only emerge under load — an app that responds in 50ms in development may return 504 errors when 50 users hit it simultaneously if a connection pool is too small.",
    "common_mistakes": [
        "Not testing against a production-like environment with realistic data volumes.",
        "Only measuring average response time — p99 latency reveals the worst user experience.",
        "Not monitoring database query counts during load tests — N+1 patterns become obvious at scale.",
        "Running load tests from a single machine — saturates the load generator, not the application server."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "profiling",
        "tail_latency",
        "connection_pooling",
        "database_indexing"
    ],
    "prerequisites": [
        "profiling",
        "connection_pooling",
        "rate_limiting"
    ],
    "refs": [
        "https://k6.io/docs/",
        "https://jmeter.apache.org/"
    ],
    "bad_code": "# No load test — assuming dev performance scales:\n# Dev: 10ms response, 1 user\n# Production launch: 200 concurrent users\n# Result: DB connection pool exhausted (max 10 connections)\n# All requests fail with 'Too many connections' — avoidable",
    "good_code": "# k6 load test — ramping up to 200 concurrent users:\nimport http from 'k6/http';\nimport { check } from 'k6';\nexport let options = {\n  stages: [\n    { duration: '30s', target: 50 },\n    { duration: '1m',  target: 200 },\n    { duration: '30s', target: 0 },\n  ]\n};\nexport default function() {\n  let res = http.get('https://staging.example.com/api/users');\n  check(res, { 'status 200': r => r.status === 200 });\n}",
    "quick_fix": "Run k6 or Locust against your staging environment before major releases — target your expected peak traffic × 1.5 and look for response time degradation, not just error rates",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/load_testing",
        "html_url": "https://codeclaritylab.com/glossary/load_testing",
        "json_url": "https://codeclaritylab.com/glossary/load_testing.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": "[Load Testing](https://codeclaritylab.com/glossary/load_testing) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/load_testing"
            }
        }
    }
}