Home / Insights / Architecture and Modernization
Architecture and Modernization
Edge Computing for Web Apps: CDN Functions, Edge Databases and Where Latency Really Comes From
Edge functions and globally replicated databases promise faster web apps for users everywhere. They help in specific places and add complexity in others. This guide explains where latency actually comes from and how to decide what belongs at the edge.
TopicsArchitecture and ModernizationWeb and SaaS Development
Key takeaways
- Measure first: for most web apps, latency comes from round trips to a distant origin and database, not from the speed of the code itself.
- CDN functions are excellent for small, stateless work at the request boundary: redirects, header and cache-key logic, A/B routing and token checks.
- Running application logic at the edge only helps if the data it needs is also nearby; an edge function that calls a single-region database can be slower than a regional server.
- Edge databases and read replicas reduce read latency, but writes still go to a primary, so you must design for replica lag and session consistency.
- Adopt edge computing incrementally, one route at a time, with latency budgets and observability in place before and after.
On this page
- Where does web app latency actually come from?
- What are CDN functions good for?
- What changes when you move data to the edge?
- How should you decide what to move to the edge?
- How do you implement edge computing safely?
- What are the risks and costs?
- Checklist: is your web app ready for the edge?
- Frequently asked questions
- Sources and methodology
Every few years a new architecture promises to make web applications fast for everyone, everywhere. The current version is edge computing: running code and storing data in points of presence close to users rather than in one central cloud region. CDN providers now let you run functions in their networks, and several databases offer global read replicas designed to sit alongside those functions.
For CTOs and architects serving users across Australia, Europe, the US and Southeast Asia, this is a genuine opportunity. It is also an easy way to add cost and complexity without improving what users feel. This article explains where latency really comes from, what CDN functions and edge databases do well, how to decide what to move, how to implement it safely, and what it costs. It reflects the situation as of September 2025.
Where does web app latency actually come from?
Before deciding what to move to the edge, break down a slow request. Google’s guidance on Time to First Byte (TTFB) is a useful frame. TTFB covers redirects, service worker start-up, DNS lookup, connection and TLS set-up, and the request up to the first byte of the response. web.dev suggests 0.8 seconds or less as a rough guide for a good TTFB and treats more than 1.8 seconds as poor, while noting that TTFB is not a Core Web Vital in itself.
The usual suspects
- Distance to the origin. Every round trip from Sydney or Singapore to a server in Europe or the eastern US adds network delay. TLS and connection set-up multiply that cost.
- Chatty back ends. A page that makes several sequential calls from server to database pays the database round trip each time. If the database is far from the server, this dominates.
- Uncacheable responses. Personalised pages, cookies that vary every response and missing cache headers force every request back to the origin.
- Cold starts and slow code. Real, but usually smaller than the network costs above for typical business applications.
Measure before you move
Use real-user monitoring segmented by country, and server-side tracing that separates network time, application time and database time. If most time is spent in the database, moving the function to the edge will not help. If most time is spent in connection set-up to a distant region, a CDN and edge logic can help a great deal.
For example, an Australian SaaS platform with European customers might find that static assets are already cached by its CDN, that the HTML for logged-in pages is generated in Sydney, and that each page makes four sequential database queries. The best first step there is reducing those queries and caching shared data, not moving rendering to the edge.
What are CDN functions good for?
CDN providers offer two broad kinds of edge compute. The first is very lightweight code that runs on every request at the CDN boundary. The second is a fuller runtime that can call other services and run more complex logic.
Two tiers at AWS
AWS’s own comparison of CloudFront Functions and Lambda@Edge shows the trade-off clearly:
| Attribute | CloudFront Functions | Lambda@Edge |
|---|---|---|
| Runtime | JavaScript (ECMAScript 5.1 compliant) | Node.js and Python |
| Triggers | Viewer request and response | Viewer and origin request and response |
| Scale | Up to millions of requests per second | Up to 10,000 requests per second per Region |
| Maximum execution time | Submillisecond | Up to 30 seconds |
| Maximum memory | 2 MB | 128 MB (viewer) to 10,240 MB (origin) |
| Network and file system access | No | Yes |
| Request body access | No | Yes |
AWS positions the lightweight tier for cache-key normalisation, header manipulation, redirects, URL rewrites and request authorisation, and the fuller tier for work that needs libraries, network calls or the request body.
Isolate-based runtimes
Cloudflare Workers take a different approach. According to Cloudflare’s explanation of how Workers works, code runs in V8 isolates across its network rather than in a container or virtual machine per function. Cloudflare states that an isolate starts roughly 100 times faster than a Node process in a container or VM and uses an order of magnitude less memory at start-up. The same page warns that isolates are short-lived and that you should not rely on global mutable state between requests.
Good first uses for CDN functions
- Redirects and URL rewrites, including locale and region routing.
- Security headers and simple bot or geography rules.
- Validating a signed token or cookie before a request reaches the origin.
- Normalising cache keys so more responses can be served from cache.
- A/B test assignment that must happen before the page is cached.
These are stateless, small and close to the CDN’s core job. They rarely need data from your database, so they deliver latency gains without data-consistency problems.
What changes when you move data to the edge?
Running application logic at the edge is attractive, but the logic usually needs data. If your edge function in Frankfurt queries a database in Sydney, every query crosses the world. A regional server that sits next to its database can be faster for that request. This is the most common edge mistake I see in architecture reviews.
Read replicas close to users
Edge-oriented databases address this with read replicas in several regions. Cloudflare’s documentation for D1 global read replication, which is in beta at the time of writing, illustrates the pattern well:
- Replicas are read-only and updated asynchronously, so a replica can be briefly behind the primary (replica lag).
- All writes are forwarded to a single primary database.
- A sessions mechanism uses bookmarks so that a user’s later reads see at least the state of their earlier writes, giving sequential consistency within a session.
Other databases implement this differently, but the underlying trade-off is the same: reads get faster and closer; writes still travel to one place; and your application must decide how much staleness each screen can tolerate.
Classify your data
| Data type | Examples | Edge suitability |
|---|---|---|
| Static or versioned | Product catalogue, content, configuration | Excellent: cache or replicate widely |
| Read-heavy, tolerant of brief lag | Search results, dashboards, public profiles | Good: read replicas with session consistency |
| User-specific, read-your-writes | Cart, settings, drafts | Possible with sessions or bookmarks; test carefully |
| Strongly consistent, write-heavy | Payments, inventory reservations, bookings | Keep near the primary; avoid edge writes |
| Regulated or residency-bound | Health records, some government data | Only where replication regions are allowed |
Data residency
Replicating data globally may conflict with contractual or legal residency requirements. Before enabling replication, check where replicas are placed and whether you can restrict regions. For health or government clients, the answer often is to keep sensitive data in one region and move only non-sensitive reads to the edge.
How should you decide what to move to the edge?
Treat edge computing as an optimisation for specific routes, not as a platform migration. A simple decision model works well:
| Option | Best for | Main trade-off |
|---|---|---|
| CDN caching only | Static assets, public pages, cacheable APIs | Requires good cache headers and invalidation |
| Lightweight CDN functions | Redirects, headers, token checks, routing | Strict limits; no network or body access |
| Full edge runtime, data in region | Personalisation that needs little data | Each data call can cross regions |
| Edge runtime plus read replicas | Read-heavy global apps | Replica lag; consistency design |
| Multi-region application servers | Write-heavy apps with users in several continents | Higher operating cost and complexity |
| Single region, optimised | Most internal and regional business apps | Distant users see higher latency |
Questions to ask for each route
- Where are the users of this route, and what is their current TTFB by country?
- Which part of the request takes the time: network, compute or database?
- Can the response be cached, fully or partly?
- What data does the logic need, and how stale can it be?
- Are there residency or compliance constraints on that data?
- Does the edge runtime support the libraries and APIs this code needs?
If the answer to question three is yes, start with caching. If the logic needs no data, a CDN function is likely the right tool. If it needs read-only data that can be slightly stale, consider replicas. If it needs strongly consistent writes, keep it close to the primary database. For guidance on how much redundancy is worth paying for, see our article on setting availability targets.
How do you implement edge computing safely?
The teams that succeed with edge computing introduce it gradually and measure each step. A sensible sequence:
- Baseline. Record TTFB, Largest Contentful Paint and error rates by country for the routes you care about, using real-user data.
- Fix caching. Set explicit cache headers, remove cookies that break caching on public pages, and normalise cache keys. This alone often produces the largest improvement.
- Move boundary logic. Shift redirects, header rules and token validation into CDN functions, and remove those responsibilities from the origin.
- Pilot one dynamic route. Choose a read-heavy route with users far from your origin. Implement it at the edge with data from a replica or cache, and keep the origin version as a fallback behind a feature flag.
- Compare. Measure the pilot against the baseline for the same countries. Check correctness as well as speed, especially after writes.
- Expand or stop. Roll out to more routes only if the gain is real and the operational burden is acceptable.
Engineering practices that matter
- Portability. Write edge code against standard Web APIs such as
fetch,RequestandResponsewhere possible, and keep provider-specific bindings behind a thin adapter. Our article on cloud vendor lock-in explains how much coupling is reasonable. - Observability. Edge functions run in many locations. Make sure logs and traces carry a request ID that follows the request to the origin and database.
- Testing. Test edge code locally with the provider’s emulator and in a staging environment on the real network. Include tests for replica lag, such as reading immediately after writing.
- Secrets. Keep secrets in the provider’s secret store, scope them narrowly and rotate them. An edge function that validates tokens is part of your security perimeter.
What are the risks and costs?
Complexity
Every new runtime adds deployment pipelines, monitoring and skills. An edge layer, a regional origin and a replicated database are three moving parts that can fail independently. Make sure the benefit is measurable before adding them.
Consistency bugs
Replica lag produces subtle bugs: a user saves a setting and the next page shows the old value; an administrator changes a price and some regions see it later. Session-based consistency tools help, but only if every relevant code path uses them.
Runtime limits
Edge runtimes deliberately restrict memory, execution time, available APIs and package size. Some Node.js libraries will not run. Check limits before committing, as the AWS comparison above shows how different the tiers can be.
Cost model
Pricing for edge compute is usually per request and per unit of compute time, and edge databases often charge per row read and written. Model costs with your real traffic, including bots, and set budget alerts. The FinOps habits in our article on cloud cost optimisation apply directly.
Vendor coupling
Edge platforms differ significantly. Bindings to a specific key-value store, database or queue tie your code to that provider. Accept that coupling where it gives clear value, and keep a path back to a regional deployment.
Checklist: is your web app ready for the edge?
- You have real-user latency data by country and know which routes are slow for whom.
- Tracing shows whether time is spent in network, compute or database for those routes.
- Cache headers are explicit and public content is served from the CDN.
- Boundary logic (redirects, headers, token checks) is candidate for lightweight CDN functions.
- Each dynamic route has a documented staleness tolerance.
- Write paths stay close to the primary database.
- Data residency requirements are known and replica regions are checked against them.
- Edge code uses standard Web APIs where possible, with provider bindings isolated.
- Observability carries request IDs from edge to origin to database.
- Costs are modelled with real traffic and budget alerts are set.
If you can tick most of these, you are ready to pilot one route. If not, start with measurement and caching; they are cheaper and often enough. PoliteTech’s cloud application development team designs cloud-native and serverless architectures on AWS, Azure and Google Cloud, and can help you measure where your latency comes from before you decide what to move.
Frequently asked questions
Will moving our app to the edge make it faster for everyone?
Not automatically. Edge compute shortens the distance to users, but if each request still calls a database in one distant region, the gain can disappear. Measure where time is spent first, then move the parts that benefit.
What is the difference between a CDN function and a serverless function?
CDN functions run inside the CDN at the request boundary, often with strict limits on memory, run time and network access. Regional serverless functions run in one cloud region with fewer limits and closer access to your databases.
Do we need an edge database to use edge functions?
No. Many valuable edge uses, such as redirects, header rules and token checks, need no database. You only need replicated data when edge logic must read application data with low latency.
How do we avoid users seeing stale data after they save something?
Use the consistency features your database offers, such as session bookmarks that ensure later reads see earlier writes, or route reads that must be fresh to the primary. Test the read-after-write path explicitly.
Is edge computing suitable for regulated data?
Sometimes. Check where replicas and logs are stored and whether regions can be restricted. Many regulated systems keep sensitive records in one approved region and use the edge only for non-sensitive content and routing.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- web.dev (Google): Time to First Byte (TTFB) — accessed 9 November 2026. Definition of TTFB, what it includes, and the 0.8 s good and 1.8 s poor thresholds.
- AWS: Differences between CloudFront Functions and Lambda@Edge — accessed 9 November 2026. Runtime, scale, execution time, memory and access limits of the two CloudFront edge compute tiers, and recommended uses.
- Cloudflare Docs: How Workers works — accessed 9 November 2026. Isolate-based execution model, start-up and memory comparisons, and the advice against global mutable state.
- Cloudflare Docs: D1 global read replication (beta) — accessed 9 November 2026. Read-only asynchronous replicas, writes forwarded to a primary, replica lag and session-based sequential consistency with bookmarks.
Related reading
Continue your research
Which of your routes would actually get faster at the edge?
Share your traffic by country and current latency data. We will help you find where time is spent and which changes, from caching to edge functions, are worth making first.
