Edge Computing: Practical Use Cases I Actually Tested
Running code at the edge makes things faster -- I know. But when specifically should you use it? I ran some tests.
I get what the edge is, but when do you use it?
Run code on a server physically close to the user. Simple concept. But "so, does my project need it?" wasn't a question I could answer right away. So I tested a few things myself.
Test 1: API redirect
We had logic that routed users to different backend servers based on their region. Previously, this was handled at an API Gateway in Singapore, with an average round-trip of 89ms for users in Korea.
Moved it to Cloudflare Workers and it dropped to 12ms. Processed right at the Korean edge node. This one clearly worked.
Test 2: A/B test branching
Doing A/B test branching on the server slows down the response. Doing it on the client causes a flash of content. The edge solves both.
Used Vercel Edge Middleware to check a cookie and serve different pages based on A/B group. Branching happened in under 1ms with no flicker. This was pretty practical.
(This one genuinely impressed me.)
Test 3: Image optimization
I tried doing device-based image sizing at the edge. Check the User-Agent, serve smaller images to mobile, larger ones to desktop.
Hit a wall here. Image resizing is CPU-intensive, and edge environments have tight CPU limits. Cloudflare Workers has a 10ms CPU time limit. Resizing large images blows right past that.
Ended up realizing image optimization is better handled by CDN image transformation features (like Cloudflare Image Resizing) rather than at the edge. Learned that the edge isn't a silver bullet.
Edge constraints
Runtime limitations are significant. You can't use all Node.js APIs. Modules like fs and net don't exist. Many npm packages aren't edge-compatible either. Once, I tried using bcrypt at the edge, couldn't, and had to swap in @noble/hashes.
And there's the execution time limit. Vercel Edge Functions cap at 25 seconds. Cloudflare Workers on the free plan gets 10ms of CPU time. You can't run complex logic with multiple DB queries.
Where edge actually makes sense
Region-based routing, A/B test branching, auth token validation, header manipulation, redirect logic. "Lightweight but needs to be fast" -- that's the edge sweet spot.
Conversely, anything that needs DB access, heavy computation, or depends on Node.js-specific APIs belongs on a regular server.
The decision criteria is simple: "Does this logic need a database?" If yes, server. If no, the edge is worth considering. Though even this depends on the case.