When we first measured our API response times across different regions, the results were sobering. Users in Asia-Pacific were experiencing latencies 3-4x higher than users in North America. The root cause was simple: all our compute was centralized in US-East.
The Migration Strategy
We did not attempt a big-bang migration. Instead, we adopted an incremental approach that allowed us to validate each step before proceeding.
Phase 1: Static Asset Distribution
The first and easiest win was distributing static assets globally. By moving JavaScript bundles, images, and CSS to edge locations, we immediately reduced page load times by 30%.
Phase 2: API Response Caching
Next, we implemented intelligent caching at the edge for API responses. Not all responses can be cached, but for those that can — like product catalogs, configuration data, and public content — the impact was dramatic.
// Edge caching middleware
export async function onRequest(context) {
const cacheKey = new Request(context.request.url, context.request);
const cache = caches.default;
let response = await cache.match(cacheKey);
if (response) {
return response; // Cache hit
}
response = await context.next();
if (response.status === 200) {
response = new Response(response.body, response);
response.headers.set('Cache-Control', 'public, max-age=300');
context.waitUntil(cache.put(cacheKey, response.clone()));
}
return response;
}
Phase 3: Compute at the Edge
The final and most impactful phase was moving actual compute workloads to the edge. This included request routing, authentication, data transformation, and personalization logic.
Results
After completing all three phases, our metrics showed remarkable improvement:
| Metric | Before | After | Improvement |
|---|---|---|---|
| P50 Latency (Global) | 320ms | 128ms | 60% |
| P99 Latency (APAC) | 1,200ms | 280ms | 77% |
| Cache Hit Rate | 0% | 72% | N/A |
| Origin Load | 100% | 31% | 69% reduction |
The most satisfying result was seeing our APAC latency drop from over a second to under 300ms. For our users in that region, the application went from feeling sluggish to feeling instantaneous.
Lessons Learned
Edge computing is not a silver bullet. It works best for workloads that are read-heavy, can tolerate eventual consistency, and benefit from geographic proximity to users. For write-heavy workloads that require strong consistency, a centralized architecture may still be the better choice.