The database is almost always the bottleneck. You can deploy your API to 300 edge locations, cache aggressively, and optimize every handler — but if every write funnels through a single PostgreSQL instance in US-East, your global latency story falls apart.
Edge databases change this equation by distributing data storage alongside compute. But they come with real tradeoffs that every architect needs to understand before migrating.
The Centralized Model
Traditional architectures deploy a single database (or a primary-replica pair) in one region. All writes go to the primary. Reads may hit replicas, but replication lag means stale data is always a risk.
// Traditional centralized architecture
// Everything routes to one region
Client (Tokyo) → CDN Edge → API Server (us-east-1) → PostgreSQL (us-east-1)
↕
150ms network 20ms query = 170ms+ total
Client (London) → CDN Edge → API Server (us-east-1) → PostgreSQL (us-east-1)
↕
80ms network 20ms query = 100ms+ total
The Edge Database Model
Edge databases replicate data to multiple locations. Reads are local (1-5ms). Writes either go to a central coordinator or use conflict-free replicated data types (CRDTs) for eventual consistency.
// Edge database architecture
// Reads are local, writes propagate
Client (Tokyo) → Edge Function (Tokyo) → Edge DB Replica (Tokyo)
↕
2ms network 1ms query = 3ms total
Client (London) → Edge Function (London) → Edge DB Replica (London)
↕
3ms network 1ms query = 4ms total
Consistency Models Compared
| Model | Read Latency | Write Latency | Consistency | Use Case |
|---|---|---|---|---|
| Single-region SQL | 1-5ms (local) / 50-200ms (remote) | 1-5ms | Strong | Financial transactions |
| Read replicas | 1-10ms | 1-5ms (primary only) | Eventual (lag: 10-100ms) | Read-heavy workloads |
| Edge KV store | 1-5ms (global) | 10-60ms (propagation) | Eventual (sub-second) | Caching, sessions, config |
| Edge SQL (SQLite-based) | 1-5ms (global) | 20-100ms (coordinator) | Sequential (single writer) | License data, user profiles |
| Distributed SQL (Spanner-type) | 5-20ms (global) | 20-200ms (consensus) | Strong (Paxos/Raft) | Global transactions |
Query Pattern Analysis
The right database depends on your read/write ratio and consistency requirements:
License Validation (99% Reads)
License validation is an ideal edge database workload. Reads dominate — a license is validated thousands of times but updated rarely (plan change, renewal, revocation). An edge SQLite replica with 5-minute write propagation delivers 1-3ms reads globally with no practical staleness risk.
// Read path: edge replica (1-3ms)
const license = await db.prepare(
'SELECT key, plan, domains, expires_at, status FROM licenses WHERE key = ?'
).bind(licenseKey).first()
// Write path: coordinator (20-80ms, happens rarely)
// License created → writes to central → replicates to 300+ edge replicas
await db.prepare(
'UPDATE licenses SET status = ?, updated_at = ? WHERE key = ?'
).bind('active', Date.now(), licenseKey).run()
Analytics Ingestion (99% Writes)
Write-heavy workloads are edge databases' weakness. Each write must coordinate through a central point (or accept conflicts). For high-volume event streams, buffer writes locally and batch-flush to a centralized analytics store:
// Buffer events locally, flush in background
const buffer = []
const logEvent = (event) => {
buffer.push({ ...event, timestamp: Date.now(), region: REGION })
}
// Background flush every 10 seconds
setInterval(async () => {
if (buffer.length === 0) return
const batch = buffer.splice(0, buffer.length)
await analyticsDB.batch(
batch.map(e => analyticsDB.prepare(
'INSERT INTO events (type, data, ts, region) VALUES (?, ?, ?, ?)'
).bind(e.type, JSON.stringify(e.data), e.timestamp, e.region))
)
}, 10000)
Migration Strategy
Moving from centralized SQL to an edge database doesn't require a big-bang migration. A phased approach minimizes risk:
- Phase 1: Edge cache layer — Add a KV cache in front of your existing database. Cache reads at the edge with 5-minute TTL. This alone cuts P50 latency by 80%.
- Phase 2: Read replica at edge — Deploy an edge SQLite replica that syncs from your primary. Route reads to the replica, writes to the primary.
- Phase 3: Edge-native schema — Redesign your schema for edge-first patterns: denormalized reads, event-sourced writes, CQRS separation.
Cost Comparison
| Database | Free Tier | $50/month Gets You | Global Reads |
|---|---|---|---|
| PostgreSQL (RDS) | 750 hrs/month (micro) | 1 region, 2 vCPU, 1GB RAM | No (single region) |
| PlanetScale | 5GB, 1B reads | 25GB, global replicas | Yes (read replicas) |
| Edge SQLite (D1-type) | 5GB, 5M reads/day | Unlimited reads, 50GB | Yes (native) |
| Google Spanner | None | 1 node ($0.90/hr) | Yes (strong consistency) |
When to Stay Centralized
Edge databases aren't always the answer. Stay centralized when:
- Strong consistency is non-negotiable — Financial transactions, inventory management, booking systems
- Complex joins dominate — Edge databases typically have limited JOIN support
- Write volume exceeds read volume — The coordination overhead outweighs the read latency gains
- Your users are in one region — If 90% of traffic comes from North America, a US-East database is already "close enough"
For license validation, API key management, and configuration storage — workloads with extreme read bias and global distribution requirements — edge databases deliver a 10-50x latency improvement over centralized SQL, at comparable or lower cost.
Ship licensing in your next release
5 licenses, 500 validations/month, full API access. Set up in under 5 minutes — no credit card required.