This design implements Azure Cosmos DB as a globally distributed, multi-model database.
Topology: The Cosmos DB account is a global PaaS resource. It is accessed securely via Private Endpoints from the Spoke VNet (where the App resides).
+--------------+ +--------------------------+ +--------------+
| Global User | | HUB VNet | | SPOKE VNet |
| | | (DNS Resolver) | | (Workload) |
+------+-------+ +------------+-------------+ +------+-------+
| | |
v | (Peering) |
+------+-------+ v v
| Front Door | +------------+-------------+ +------+-------+
| (Routing) |---------->| Private DNS Zone |<----------| App / API |
+--------------+ | (privatelink.documents) | | (Compute) |
+--------------------------+ +------+-------+
|
v
+--------------+
| Cosmos DB |
| (Private) |
+--------------+
PRIMARY REGION (East US)
+-----------------------------------------------------------------------+
| HUB VNet: vnet-hub (10.0.0.0/16) |
| +-----------------------+ |
| | Private DNS Zone | |
| | (privatelink.documents)| |
| +-----------|-----------+ |
| | |
| v (Peering) |
+---------------|-------------------------------------------------------+
|
+---------------|-------------------------------------------------------+
| SPOKE VNet: vnet-cosmos-spoke (10.1.0.0/16) |
| +-----------------------+ +-----------------------+ |
| | Subnet: App | | Subnet: PrivateLink | |
| | [Web API VM] |------>| [Private Endpoint] | |
| | (Processes Request) | | (10.1.1.5) | |
| +-----------------------+ +-----------|-----------+ |
+-----------------------------------------------|-----------------------+
|
v
+-----------------------+
| Cosmos DB Account |
| (Write Region: East) |
+-----------------------+
|
| (Global Replication)
v
SECONDARY REGION (West US)
+-----------------------------------------------------------------------+
| DR SPOKE VNet |
| +-----------------------+ |
| | [Web API DR] | |
| | (Reads from West) | |
| +-----------------------+ |
| | |
| v |
| +-----------------------+ |
| | Cosmos DB Replica | |
| | (Read Region: West) | |
| +-----------------------+ |
+-----------------------------------------------------------------------+
* Add West US as a read region.
* Enable Service-Managed Failover.
* If East US dies, Azure promotes West US to Write Region automatically.
1. User: Sends request to Front Door.
2. Route: Front Door routes to Web API in East US.
3. Process: API processes logic.
4. Query: API queries Cosmos DB via Private Endpoint (10.1.1.5).
5. Replication: Cosmos DB engine replicates data to West US asynchronously.
6. Read: User in West US hits Front Door -> Web API DR -> Reads from West US replica (<10ms latency).
1. Search: "Private DNS zones" -> + Create.
2. Resource Group: rg-hub-dns.
3. Name: privatelink.documents.azure.com (Exact name for Cosmos).
4. Create.
5. Link to Hub:
* Go to Zone -> Virtual network links -> + Add.
* Name: link-to-hub.
* Virtual network: vnet-hub.
* OK.
6. Link to Spoke:
* + Add.
* Name: link-to-spoke.
* Virtual network: vnet-cosmos-spoke.
* OK.
1. Search: "Azure Cosmos DB" -> + Create.
2. API: Azure Cosmos DB for NoSQL (formerly Core/SQL).
3. Resource Group: rg-design25-cosmos.
4. Account Name: cosmos-global-corp-[uniqueid].
5. Location: East US.
6. Capacity mode: Serverless (Best for labs) or Provisioned.
7. Global Distribution:
* Geo-Redundancy: Enable.
* Multi-region writes: Disable.
8. Networking:
* Connectivity method: Private endpoint.
* Add private endpoint:
* Name: pe-cosmos.
* Subscription/Resource Group: rg-design25-cosmos.
* Location: East US.
* Target sub-resource: Sql (for NoSQL API).
* Virtual Network: vnet-cosmos-spoke.
* Subnet: snet-workload.
* Integrate with private DNS zone: Yes.
* Private DNS Zone: privatelink.documents.azure.com.
9. Review + create -> Create.
1. Go to Cosmos Account -> Replicate data globally.
2. Click on the map (e.g., West US).
3. Save. (This starts data replication).
1. Login to a VM in the Spoke.
2. Nslookup: nslookup cosmos-global-corp-[uniqueid].documents.azure.com.
* Result should be 10.1.x.x (Private IP).
3. Data Explorer:
* Go to Portal -> Data Explorer.
* New Container -> Database ToDoList -> Container Items.
* Add Item: {"id": "1", "task": "Test"}.
4. Verify Replication:
* Wait a few minutes.
* The data is now in West US too.
1. Go to Cosmos Account -> Replicate data globally.
2. Click on the map (e.g., West US).
3. Save. (This starts data replication).
1. Go to Data Explorer.
2. Create a Database ToDoList -> Container Items.
3. Add a document {"id": "1", "task": "Test"}.
4. It is now safely stored and replicated.