7 views
DynamoDB Global Tables give you multi-region active-active with asynchronous replication. After a write in ap-south-1, a read in eu-west-1 can miss it for hundreds of milliseconds (or more under load). Users who submit a form and immediately GET their profile see ghosts unless you design for read-your-writes (RYW).
⚡ TL;DR: Stick the session to the region that took the write; or return a version/ConsistentRead token the client echoes; or read from the writer region until a version vector says replicas caught up. Multi-region checkout patterns: Production-Grade Multi-Region E-Commerce Checkout on AWS. Idempotent writes still matter: Lambda Powertools Idempotency.
Read-Your-Writes on Global Tables: production guidance
Route a user sticky to one region for the session. Writes and reads share a replica; cross-region is for failover and users elsewhere.python
Failover must clear or rewrite the cookie when the primary is unhealthy.
# edge: choose region from cookie
def region_for(request) -> str:
r = request.cookies.get("ryw_region")
if r in {"ap-south-1", "eu-west-1", "us-east-1"}:
return r
return request.geo_nearest_region()
Version tokens for cross-region reads
On write, returnversion (monotonic per item) or DynamoDB item attribute incremented atomically. Client sends If-Match-Version / X-Min-Version on subsequent reads; if the local replica is behind, proxy read to the writer region or wait briefly.
python
# write path
resp = table.update_item(
Key={"pk": pk},
UpdateExpression="SET profile = :p ADD version :one",
ExpressionAttributeValues={":p": profile, ":one": 1},
ReturnValues="UPDATED_NEW",
)
return {"version": int(resp["Attributes"]["version"])}
# read path
def read_profile(pk: str, min_version: int | None, local, writer):
item = local.get_item(Key={"pk": pk}).get("Item")
if not min_version:
return item
if item and int(item.get("version", 0)) >= min_version:
return item
# ✅ Fall back to writer region for RYW
return writer.get_item(Key={"pk": pk}).get("Item")
python
# ❌ Always ConsistentRead in every region — GT does not make remote ConsistentRead see latest global write
table.get_item(Key=..., ConsistentRead=True)
When lag becomes an incident
Instrument replication lag proxies: time from write timestamp attribute to local visibility (canaries that write in A and poll B). Alert when p99 lag exceeds UX budget. During regional congestion, prefer stickiness over cross-region read storms.Conflict resolution
Two regions writing the same key need last-writer-wins awareness or application merge. RYW does not replace conflict design—document which fields are region-owned.Closing checklist
✅ Dos – ✅ Sticky sessions for the common RYW case – ✅ Return and honor version tokens for cross-region UX – ✅ Canary measure A→B visibility lag – ✅ Fail sticky cookie over on regional failover – ✅ Keep idempotency keys on multi-region writes ❌ Don’ts – ❌ Don’t assumeConsistentRead is globally consistent on Global Tables
– ❌ Don’t fan-out every read to all regions
– ❌ Don’t ignore dual-write conflicts on hot keys
– ❌ Don’t hide lag behind unbounded client sleeps
– ❌ Don’t store RYW tokens that never expire in localStorage without care
Related reading
- Production-Grade Multi-Region E-Commerce Checkout on AWS
- Lambda Powertools Idempotency: DynamoDB Keys That Survive Retries
- Lambda Warm Pools: Low-Latency Backends for Coding Agent Tools
- System Design Interview Cheat Sheet
Watch: 100 Days of AI on YouTube
Short videos from CheatCoders, one AI engineering topic per day.
Most viewed
- Python Decorators Explained: From Simple Wrappers to Production Patterns
- Claude Code vs Cursor vs GitHub Copilot: Choose by Workflow, and Set Up One Repo That Works With All Three
- AI Agent Frameworks in 2025: LangGraph vs CrewAI vs AutoGen vs Raw API
- Python String Methods: Every str Method With Real Production Examples
- Css Animation Performance: Performance-Optimized Motion for Modern UIs
Newly added
- AWS Systems Manager Parameter Store: Hierarchical Runtime Config for Coding Agents
- Amazon Cognito Identity Pools: Federate Coding-Agent Tool Callers Without Long-Lived Keys
- Amazon Athena for Coding Agents: Query Tool Audit Logs and Eval Traces on S3 Without a Warehouse
- AWS Batch for Coding Agents: Parallel Overnight PR Reviews and Long-Running Jobs Without Lambda Timeouts
- Amazon Bedrock Prompt Management: Version and A/B Test Coding-Agent System Prompts
Deep-dive PDF
Get the expanded guide for this post — extra diagrams-style checklists, failure modes, and a production walkthrough. Free when you subscribe to CheatCoders.
Already subscribed? or open the subscribe page.
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.

Pingback: DynamoDB Capacity Mode Switching: On-Demand to Provisioned Around Cliffs - CheatCoders