Edge Computing Architecture
Design systems that push computation to the network edge for lower latency, reduced bandwidth, and real-time processing. Covers edge vs cloud trade-offs, CDN workers, IoT edge, edge databases, and the patterns that make edge computing practical.
Edge computing moves computation closer to users and data sources. Instead of sending every request to a centralized data center, edge nodes process data at the point of creation or consumption. The result: lower latency (< 50ms globally), reduced bandwidth costs, and the ability to process real-time data streams.
Where is “The Edge”?
Far Edge: On-device (smartphone, IoT sensor, vehicle)
Near Edge: Local server (factory floor, retail store, cell tower)
Network Edge: CDN PoPs, cloud edge locations (100+ locations)
Cloud Edge: Regional data centers (10-30 locations)
Cloud Core: Centralized data centers (3-5 regions)
Edge Computing Patterns
CDN Workers
Execute code at CDN edge locations (200+ PoPs globally):
// Cloudflare Worker: A/B testing at the edge
export default {
async fetch(request) {
const url = new URL(request.url);
// Determine variant (no round-trip to origin)
const cookie = request.headers.get('cookie') || '';
let variant = cookie.match(/ab_test=(\w+)/)?.[1];
if (!variant) {
variant = Math.random() < 0.5 ? 'control' : 'experiment';
}
// Rewrite URL to correct variant
url.pathname = `/${variant}${url.pathname}`;
const response = await fetch(url.toString(), request);
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.set('Set-Cookie', `ab_test=${variant}; path=/;`);
return modifiedResponse;
}
};
Edge API
// Edge function: Geo-aware API responses
export default {
async fetch(request, env) {
const country = request.cf?.country || 'US';
const city = request.cf?.city || 'Unknown';
// Serve from edge KV store (no origin round-trip)
const localData = await env.KV.get(`products:${country}`, 'json');
if (localData) {
return new Response(JSON.stringify(localData), {
headers: { 'Content-Type': 'application/json' }
});
}
// Fall back to origin
return fetch(`https://api.origin.com/products?country=${country}`);
}
};
Edge Databases
| Database | Type | Replication | Use Case |
|---|---|---|---|
| Cloudflare D1 | SQLite at edge | Automatic to 200+ PoPs | Simple queries, read-heavy |
| Turso (libSQL) | Distributed SQLite | Multi-region replicas | Low-latency reads globally |
| PlanetScale | MySQL-compatible | Global read replicas | Vitess-based, MySQL workloads |
| Neon | PostgreSQL | Read replicas at edge | Serverless Postgres |
| DynamoDB Global Tables | NoSQL | Multi-region active-active | AWS-native, key-value |
Edge vs Cloud Decision
Process at the edge when:
✅ Latency-sensitive (< 50ms requirement)
✅ High-bandwidth source data (filter before sending to cloud)
✅ Privacy-sensitive (process locally, send aggregates)
✅ Real-time decisions (autonomous vehicles, industrial control)
✅ Offline-capable (intermittent connectivity)
Process in the cloud when:
✅ Complex computation (ML training, analytics)
✅ Cross-region data aggregation
✅ Stateful transactions requiring strong consistency
✅ Large-scale storage and processing
IoT Edge
IoT Devices (1000s)
↓ (sensor data: temperature, pressure, vibration)
Edge Gateway (1 per facility)
├── Filter: Discard noise, keep anomalies
├── Aggregate: 1-second readings → 1-minute summaries
├── Alert: Local notification for critical values
└── Forward: Send summaries to cloud (90% bandwidth reduction)
↓
Cloud Platform
├── Store historical data
├── Train ML models
├── Dashboard and analytics
└── Push updated models to edge
Anti-Patterns
| Anti-Pattern | Consequence | Fix |
|---|---|---|
| Edge for compute-heavy workloads | Edge nodes under-powered | Keep heavy compute in cloud |
| Strong consistency at the edge | High latency, defeats purpose | Eventual consistency for edge data |
| No fallback to cloud | Edge failure = total failure | Graceful fallback to origin |
| Treating edge like cloud (stateful) | Data loss, sync complexity | Stateless edge, state in cloud/edge DB |
| No observability at edge | Blind spots in 200+ locations | Edge-native logging and metrics |
Edge computing is not a replacement for cloud — it is an extension. The best architectures use edge for latency-sensitive, bandwidth-intensive tasks and cloud for compute-intensive, stateful, and analytical workloads.