{
    "slug": "cloud_region_selection",
    "term": "Cloud Region Selection",
    "category": "cloud",
    "difficulty": "intermediate",
    "short": "The decision of which cloud region(s) to deploy workloads into, balancing user latency, data residency law, cost, and service availability.",
    "long": "Cloud region selection is the design decision of where geographically your workloads, data, and traffic flow. It is not about how to provision a region (that is IaC) but about which to pick and when. The main axes are: latency to end users (closer regions feel faster, especially for chatty APIs and real-time features); data residency and compliance (GDPR, schrems II, HIPAA, Australian Privacy Principles, sovereign cloud requirements often pin data to a specific country); price (us-east-1 is typically the cheapest on AWS; ap-south-1 or sa-east-1 can be 20-50% more expensive for identical SKUs); service availability (newer services land in flagship regions first; GPU capacity and managed AI services are unevenly distributed); and disaster recovery posture (active-passive across paired regions vs. active-active multi-region).\n\nFor most PHP applications the practical default is: pick one primary region close to the majority of users, place the database there, and front the application with a CDN to mask latency for static assets. Only adopt multi-region when you have a concrete driver — regulatory split, global write latency, or an SLA that exceeds what a single region can offer. Multi-region is expensive in egress, replication lag, and operational complexity (split-brain, conflict resolution, deploy coordination).\n\nRuntime region selection matters too: latency-based DNS (Route 53, Cloud DNS) and global load balancers can route users to their nearest healthy region. For storage, choose between regional buckets (cheaper, single-region durability) and multi-region buckets (higher cost, automatic geo-replication). For data residency, ensure logs, backups, and analytics pipelines also stay in-region — it is common to lock the database to eu-west-1 then leak PII into a us-east-1 logging account.\n\nRevisit the choice when traffic patterns shift, when new regions open closer to users, or when a paired region is needed for compliance with DORA, GDPR, or sovereign cloud mandates.",
    "aliases": [
        "region choice",
        "geo placement",
        "data residency placement",
        "deployment region"
    ],
    "tags": [
        "cloud",
        "region",
        "latency",
        "data-residency",
        "compliance",
        "multi-region"
    ],
    "misconception": "Pick the region closest to you geographically. The correct heuristic is the region closest to the majority of your users (and legally permitted for their data), not where the developers sit.",
    "why_it_matters": "Region choice is sticky: data egress fees, replication design, and compliance commitments make it expensive to move later, and a wrong pick imposes permanent latency tax on every request.",
    "common_mistakes": [
        "Choosing us-east-1 by default for an EU user base, then violating GDPR and adding 100ms+ to every request.",
        "Placing the application in one region and the database in another, paying cross-region latency on every query.",
        "Going multi-region for resilience without measuring whether a single region's SLA already meets the business requirement.",
        "Forgetting that logs, backups, and analytics also count as data residency — only locking the primary database to the right region.",
        "Hardcoding region names in config so the same artefact cannot be deployed to a paired DR region without a rebuild."
    ],
    "when_to_use": [
        "When user base is concentrated in a region different from the developer's default cloud account.",
        "When data residency law (GDPR, HIPAA, sovereign cloud) restricts where personal data may be stored or processed.",
        "When latency-sensitive workloads (real-time, gaming, voice, trading) need sub-50ms response times to specific user populations.",
        "When the business SLA exceeds what a single region's published availability can provide and active-passive multi-region is justified."
    ],
    "avoid_when": [
        "An early-stage prototype with no production users — defer the decision, pick the cheapest nearby region, and revisit at scale.",
        "Workloads with no data residency constraints and global users already served well by a CDN at the edge.",
        "Internal tooling used only by a small team — optimise for developer latency, not user latency.",
        "When you cannot articulate a measurable driver (latency target, legal mandate, SLA) for multi-region complexity."
    ],
    "related": [
        "cloud_computing_models",
        "cloud_cdn",
        "cloud_storage_s3",
        "multi_cloud_strategy",
        "cloud_cost_optimisation",
        "cloud_native_patterns"
    ],
    "prerequisites": [
        "aws_fundamentals",
        "cloud_computing_models",
        "cloud_native_patterns"
    ],
    "refs": [
        "https://aws.amazon.com/about-aws/global-infrastructure/regions_az/",
        "https://cloud.google.com/about/locations",
        "https://learn.microsoft.com/en-us/azure/reliability/availability-zones-overview"
    ],
    "bad_code": "// Default boilerplate copied from an AWS tutorial — app serves mostly EU users\n// but everything is pinned to us-east-1, and the logging account is us-west-2.\n\n$config = [\n    'region'   => 'us-east-1',          // 100ms+ from EU users on every API call\n    's3'       => ['region' => 'us-east-1'],\n    'rds_host' => 'prod-db.xxxx.us-east-1.rds.amazonaws.com',\n    'logs'     => ['region' => 'us-west-2'], // PII leaks across two US regions\n];\n\n// No thought given to GDPR, latency, or where backups land.",
    "good_code": "// Region is explicit, env-driven, and aligned with the user base + residency rules.\n// Primary EU region; DR region is the paired EU region (eu-west-1 <-> eu-west-2).\n\n$region = getenv('AWS_REGION') ?: 'eu-west-1';\n\n$config = [\n    'region'   => $region,\n    's3'      => [\n        'region' => $region,\n        'bucket' => \"app-uploads-{$region}\",   // regional bucket, EU-only data\n    ],\n    'rds_host' => \"prod-db.xxxx.{$region}.rds.amazonaws.com\",\n    'logs'    => ['region' => $region],         // logs stay in jurisdiction\n    'dr_region' => 'eu-west-2',                 // paired region for failover\n];\n\n// Route 53 latency-based routing sends users to their nearest healthy region.",
    "quick_fix": "List your top three user populations and their legal data jurisdictions, then pick the cheapest region in the lowest-latency country that satisfies residency — and put the database, logs, and backups all in that same region.",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-05-22",
    "updated": "2026-05-31",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/cloud_region_selection",
        "html_url": "https://codeclaritylab.com/glossary/cloud_region_selection",
        "json_url": "https://codeclaritylab.com/glossary/cloud_region_selection.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 Region Selection](https://codeclaritylab.com/glossary/cloud_region_selection) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/cloud_region_selection"
            }
        }
    }
}