{
    "slug": "cloud_native_patterns",
    "term": "Cloud-Native Patterns",
    "category": "cloud",
    "difficulty": "intermediate",
    "short": "Stateless services, externalised config, health checks, graceful shutdown, and immutable infrastructure — the 12-Factor App extended for containers.",
    "long": "Stateless processes (sessions in Redis, files in S3), externalised config (env vars, never baked in images), immutable infrastructure (replace not patch), disposability (fast startup <10s, graceful SIGTERM), health checks (readiness+liveness), structured logging to stdout, horizontal scaling.",
    "aliases": [
        "cloud native",
        "12-factor",
        "stateless services"
    ],
    "tags": [
        "cloud",
        "architecture",
        "devops"
    ],
    "misconception": "Cloud-native requires Kubernetes — it is a set of design principles; a PHP app on ECS Fargate can be fully cloud-native.",
    "why_it_matters": "A PHP application storing sessions on local disk cannot be horizontally scaled — cloud-native stateless design enables auto-scaling.",
    "common_mistakes": [
        "Local file storage",
        "Config baked into images",
        "No graceful SIGTERM handling",
        "Slow startup delaying auto-scaling"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "containerisation",
        "kubernetes_basics",
        "twelve_factor_app"
    ],
    "prerequisites": [
        "twelve_factor_app",
        "containerisation",
        "kubernetes_basics"
    ],
    "refs": [
        "https://12factor.net/"
    ],
    "bad_code": "$_SESSION['cart'] = $data; file_put_contents('/tmp/cache',$data);",
    "good_code": "ini_set('session.save_handler','redis'); ini_set('session.save_path',getenv('REDIS_URL'));\n$s3->putObject(['Bucket'=>getenv('S3_BUCKET'),'Key'=>$path,'Body'=>$data]);",
    "quick_fix": "PHP apps become cloud-native by: storing state externally (Redis/DB), logging to stdout, reading config from env vars, and handling SIGTERM for graceful shutdown",
    "severity": "medium",
    "effort": "high",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/cloud_native_patterns",
        "html_url": "https://codeclaritylab.com/glossary/cloud_native_patterns",
        "json_url": "https://codeclaritylab.com/glossary/cloud_native_patterns.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": "[Cloud-Native Patterns](https://codeclaritylab.com/glossary/cloud_native_patterns) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/cloud_native_patterns"
            }
        }
    }
}