Two regions, both serving reads and writes, with DNS failover in under a minute when one goes dark.
The problem
Single-region apps share one fate: when the region has a bad day, so do you. Most teams know multi-region is the answer but stop at “it’s too complex”. This project shows a clean, serverless pattern where every region is identical and independent, and the global layer is just data replication plus smart DNS.
What you’ll build
- A DynamoDB global table replicated across two regions (multi-active, PITR on)
- An identical HTTP API + Lambda stack per region, deployed from one CDK app
- Optional custom domain with regional ACM certificates and API Gateway domain mappings
- Route 53 latency records + HTTPS health checks every 10 seconds so unhealthy regions drop out automatically
- A kill switch (SSM parameter) to rehearse a regional failure without breaking anything
Architecture
Route 53 (latency routing + health checks every 10s)
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
us-east-1 us-west-2
HTTP API โโถ Lambda โโถ DynamoDB replica โโโ global table โโโถ DynamoDB replica โโ Lambda โโ HTTP API
AWS services used
How it works
- ReplicateWrites in either region replicate to the other in about a second through DynamoDB global tables.
- Serve locallyRoute 53 latency routing sends each user to the closest healthy region.
- DetectHealth checks hit
/health, which verifies the in-region table and the kill switch. - Fail overTwo failed checks (about 20 seconds) and Route 53 stops answering with that region. Traffic shifts on the next DNS lookup.
Key design decisions
- Every region is self-sufficient: no cross-region calls on the request path.
- Global tables use last-writer-wins, so writes use client-generated IDs and are idempotent.
- The SSM kill switch makes failover drills boring, which is exactly what you want.
Deploy it
npm install
npx cdk bootstrap aws://ACCOUNT/us-east-1 aws://ACCOUNT/us-west-2
# Without a domain (regional URLs only)
npx cdk deploy --all
# With a domain you host in Route 53 (enables global URL + failover)
npx cdk deploy --all -c domainName=api.example.com -c zoneName=example.com -c hostedZoneId=Z123456ABCDEFG
Full prerequisites, parameters and clean-up steps are in the project README on the code page.
See it work
Flip /active-active/us-east-1/healthy to false and watch the x-served-by-region header switch to us-west-2 within about a minute. Writes made before the switch are already there.
Skills this demonstrates
Get the code
Every file needed to build this project, written as a deployable AWS CDK app and validated with the CloudFormation schema.
Leave a Reply