Edge computing moves computation from centralized data centers to locations closer to users and data sources. This reduces latency, enables real-time processing, and opens possibilities that weren’t feasible with round-trips to distant servers.
Here’s how to think about edge computing architecture.
What is Edge Computing
The Edge Spectrum
┌─────────────────────────────────────────────────────────────────┐
│ │
│ Device Edge Regional Cloud │
│ Edge Network Data Center Data Center │
│ │
│ ○──────────────○──────────────○───────────────○ │
│ │
│ Smartwatch CDN PoP AWS Region Central │
│ IoT Sensor 5G Tower Azure Region Services │
│ Mobile App ISP Edge GCP Region │
│ │
│ < 10ms 10-50ms 50-150ms 100-300ms │
│ │
└─────────────────────────────────────────────────────────────────┘
Why Edge Matters
Latency:
- Speed of light limits round-trip time
- New York to Singapore: ~230ms minimum
- Many applications need < 50ms response
Bandwidth:
- Moving data is expensive
- Process locally, send results
- Video analytics: GB/s input → KB/s output
Reliability:
- Works during network outages
- Reduces dependency on connectivity
- Critical for IoT and industrial use cases
Privacy:
- Data stays local
- Meets data residency requirements
- Reduces exposure surface
Architecture Patterns
CDN Edge
Static content and simple computation at CDN Points of Presence:
┌─────────────────────────────────────────────────────────────────┐
│ │
│ User ──► CDN Edge ──► Origin │
│ │ │
│ ├── Cache hit: return immediately │
│ ├── Edge compute: run logic │
│ └── Cache miss: fetch from origin │
│ │
└─────────────────────────────────────────────────────────────────┘
Capabilities:
- Static asset caching
- Request/response transformation
- A/B testing and personalization
- Authentication/authorization
- Rate limiting
Platforms:
- Cloudflare Workers
- AWS Lambda@Edge / CloudFront Functions
- Fastly Compute@Edge
- Vercel Edge Functions
Example: Geolocation personalization
// Cloudflare Worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const country = request.cf.country
const response = await fetch(request)
// Inject country-specific pricing
let html = await response.text()
html = html.replace('{{CURRENCY}}', getCurrency(country))
html = html.replace('{{PRICES}}', getPrices(country))
return new Response(html, {
headers: response.headers
})
}
Fog Computing
Intermediate layer between devices and cloud:
┌─────────────────────────────────────────────────────────────────┐
│ │
│ Devices ──► Fog Node ──► Cloud │
│ │ │ │ │
│ │ │ └── Long-term storage │
│ │ │ └── Heavy analytics │
│ │ │ └── Global coordination │
│ │ │ │
│ │ └── Local processing │
│ │ └── Aggregation │
│ │ └── Real-time decisions │
│ │ │
│ └── Data generation │
│ └── Simple processing │
│ │
└─────────────────────────────────────────────────────────────────┘
Use cases:
- Industrial IoT (factory floor processing)
- Smart city infrastructure
- Retail store analytics
- Healthcare monitoring
Hybrid Edge-Cloud
Partition workloads between edge and cloud:
# Decision framework
def decide_processing_location(task):
if task.latency_requirement < 50: # ms
return EDGE
if task.data_size > 10: # MB
return EDGE_THEN_CLOUD # Process, then send results
if task.requires_global_data:
return CLOUD
if task.privacy_sensitive:
return EDGE
return CLOUD # Default for complex processing
Use Cases
Real-Time Personalization
Personalize content without origin round-trip:
// Edge function for personalization
async function handleRequest(request) {
const user = await getUser(request)
const segment = classifyUser(user)
// Fetch pre-rendered variant from edge cache
const variant = await cache.get(`page:${segment}`)
// Or render at edge
const content = await renderForSegment(segment, user)
return new Response(content)
}
API Gateway at Edge
Authentication, rate limiting, and routing:
async function handleRequest(request) {
// Rate limiting
const ip = request.headers.get('cf-connecting-ip')
const rateLimit = await checkRateLimit(ip)
if (rateLimit.exceeded) {
return new Response('Too Many Requests', { status: 429 })
}
// Authentication
const token = request.headers.get('Authorization')
const auth = await validateToken(token) // JWT validation at edge
if (!auth.valid) {
return new Response('Unauthorized', { status: 401 })
}
// Route to appropriate origin
const origin = selectOrigin(request.url, auth.user)
return fetch(origin, request)
}
Image Optimization
Transform images at edge:
async function handleImage(request) {
const url = new URL(request.url)
const width = url.searchParams.get('w') || 800
const format = request.headers.get('accept').includes('webp') ? 'webp' : 'jpeg'
// Check edge cache
const cacheKey = `${url.pathname}:${width}:${format}`
const cached = await cache.match(cacheKey)
if (cached) return cached
// Fetch and transform
const image = await fetch(url.pathname)
const transformed = await resizeImage(image, width, format)
// Cache at edge
await cache.put(cacheKey, transformed.clone())
return transformed
}
IoT Data Processing
Process sensor data locally:
# Fog node processing
class FogProcessor:
def __init__(self):
self.buffer = []
self.anomaly_detector = load_model('anomaly_detector.onnx')
def process_reading(self, sensor_id, reading):
# Real-time anomaly detection
is_anomaly = self.anomaly_detector.predict(reading)
if is_anomaly:
# Immediate alert
self.alert_cloud(sensor_id, reading)
# Buffer for batch upload
self.buffer.append({
'sensor_id': sensor_id,
'reading': reading,
'timestamp': time.time()
})
# Periodic batch sync
if len(self.buffer) >= 100:
self.sync_to_cloud()
Gaming and AR/VR
Ultra-low latency requirements:
Game State
│
▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Client │◄───►│ Edge │◄───►│ Cloud │
│ (10ms) │ │ (20ms) │ │ (100ms) │
└─────────┘ └─────────┘ └─────────┘
│ │ │
└── Input └── Physics └── Matchmaking
└── Rendering └── Collision └── Leaderboards
└── Sync └── Replays
Data Patterns
Write-Local, Read-Global
Write: Device → Local Edge → Cloud (async)
Read: Any edge can serve (eventually consistent)
Aggregation Pattern
Raw Data ──► Edge Aggregation ──► Cloud Storage
1M/sec 100/sec Query
# Instead of sending every reading:
# - Calculate min, max, avg per minute
# - Send anomalies immediately
# - Store raw locally, upload batches
Edge-First with Cloud Fallback
async def getData(key):
# Try edge cache first
result = await edge_cache.get(key)
if result:
return result
# Try regional cache
result = await regional_cache.get(key)
if result:
await edge_cache.set(key, result)
return result
# Fall back to cloud
result = await cloud_api.get(key)
await edge_cache.set(key, result)
return result
Challenges
Consistency
Distributed state is hard:
# Options
1. Eventual consistency (most common for edge)
2. Session affinity (user always hits same edge)
3. Consensus protocols (expensive at edge)
4. CRDT (Conflict-free Replicated Data Types)
Deployment
Managing distributed deployments:
# GitOps for edge
apiVersion: edge.example.com/v1
kind: EdgeDeployment
metadata:
name: api-handler
spec:
regions:
- us-east
- us-west
- eu-west
- ap-southeast
rollout:
strategy: canary
steps:
- weight: 5
duration: 10m
- weight: 25
duration: 30m
- weight: 100
Observability
Monitoring distributed edge:
Central Collector
▲
│
┌──────┴──────┐
│ Metrics │
│ Traces │
│ Logs │
└──────┬──────┘
│
┌────┼────┐
▼ ▼ ▼
Edge Edge Edge
Aggregate locally, ship summaries:
- Don’t send every log line
- Pre-aggregate metrics
- Sample traces
Security
Edge increases attack surface:
Mitigations:
- Minimal code at edge
- Secrets in secure storage (not in code)
- Regular rotation
- Audit logging
- Network segmentation
When to Use Edge
Good Fit
- Latency-sensitive applications (< 100ms)
- High-bandwidth data sources (video, IoT)
- Geographic distribution of users
- Privacy/compliance requirements
- Unreliable connectivity
Poor Fit
- Complex stateful operations
- Heavy computation (use cloud)
- Strong consistency requirements
- Centralized data needed
- Simple, low-traffic applications
Key Takeaways
- Edge computing moves compute closer to users for lower latency
- CDN edge handles simple compute: auth, personalization, transformation
- Fog computing adds processing layer for IoT and industrial use cases
- Design for eventual consistency; strong consistency at edge is expensive
- Process data locally, send results; don’t move raw data unnecessarily
- Use edge for latency-sensitive paths, cloud for complex processing
- Monitor distributed edge with aggregation to avoid overwhelming central systems
- Security at edge requires different approach: minimal code, secure secrets, audit everything
- Start with CDN edge functions for web applications; they’re the easiest entry point
Edge computing enables applications that weren’t possible before. The challenge is choosing what runs where.