Platform & Infrastructure

2026-11-26

Application Patterns at the Edge: Choosing Where Work and Data Belong

Five practical edge application patterns, compared by trust boundary, data access, consistency and operational responsibility.


Platform & Infrastructure · architecture · ~10 min read · builds on: The Edge-Native Stack

An edge cloud runs application code on a provider's distributed network instead of requiring the team to provision a server for every application. The platform can receive HTTPS requests, run a function and expose managed services through configured interfaces. It does not follow that every database, file or workload runs near every user, or that the platform decides the application's access policy.

The Edge-Native Stack makes the underlying argument: infrastructure responsibility moves; it does not disappear. Traffic distribution and execution may be managed by the platform, while the team still owns decisions about authorization, data consistency, failure and recovery. This post takes the next step: how those responsibilities shape an application and its request paths.

Consider a hypothetical operations portal with a web interface and a mobile app. Staff need to read and update tickets; a separate service generates reports on a stateful host. The team must choose where to expose an API, where tickets live and how requests reach the report service. The request can enter at the edge, but the data and the service do not have to live there.

A public catalogue might need only static files and a managed API. An application coordinating payments and inventory may need its own request handler and a relational database. A specialist workload may stay on a stateful machine, with the edge controlling how requests reach it. Each is a valid architecture; the right choice depends on what the application must protect, how its data behaves and who can operate it.

Choose the boundary first, then choose the service. The useful questions are where access is enforced, where writes become authoritative, what a reader can see after a write, and what happens when a dependency fails. The answers are more durable than a provider's product list.

Five Patterns, Not Five Stages

The following paths are alternatives, not a prescription to deploy every component. For the portal, start with the ticket request: can the clients call a managed API safely, or does the team need an application API? Then choose how that API reaches data and how report requests reach the separate host. Those choices can be combined without making any one of them mandatory.

A managed data API is an HTTP service a provider operates to expose data. For example, Supabase provides a Data API over PostgreSQL; the team configures what is exposed, database grants and row-level policies. The provider operates the API, but the team remains responsible for access rules. The API can run outside the edge platform.

An application API is code the team owns. On Cloudflare, it can be a Worker that receives HTTP requests from browsers and mobile apps. The Worker can call a managed API, use a database driver or a binding, or route to an external service. The team's code defines its routes and behavior; a database binding does not automatically create a public API.

The diagram is a map of choices, not a single deployment. HTTP, SQL and bindings label how application code reaches a dependency, not types of Worker. A tunnel connector establishes the outbound connection from the origin side; the arrow shows the request's direction after that connection is established.

PatternRequest and data pathChoose it whenResponsibility to keep
Client and managed APIBrowser or mobile app → managed API → dataThe API and its policies express the operations the client needsExposed data, client identity, API grants and data policies
Edge application and managed APIClient → application API → managed APIRequests need application-owned validation or coordinationAuthorization across both hops and the failure of either service
Edge application and relational databaseClient → application API → database connectionSQL features or transactional work justify direct database accessConnection lifecycle, transaction scope and database permissions
Edge application and edge-native databaseClient → application API → bound data serviceIts data model, limits and consistency fit the workloadActual write placement, consistency, backup and recovery
Edge front door and external computeClient → edge → tunnel → origin serviceA stateful or specialised workload needs an external runtimeOrigin access, connector and host health, durable state and restore

These are logical paths, not promises about physical distance. An edge function can run near a caller while its database is regional. Measure the complete path and its dependencies before promising a latency improvement.

One implementation: Cloudflare's vocabulary

Cloudflare is a useful concrete example because it provides several of these building blocks. The generic responsibility comes first; the product is one way to implement it, not a requirement for the pattern.

ResponsibilityCloudflare exampleDecision the name does not make for you
Serve static files and run request logicWorkers and static assetsWhich paths are public, and which must run an access check first?
Give a function access to a serviceWorker bindingWhich Worker is trusted with the capability, and what may its callers do?
Store relational application dataD1Which SQL features, consistency and recovery properties does the workload need?
Reuse connections to an external databaseHyperdriveHow are the database role, user identity and transaction scoped?
Store objects or cached key-value dataR2 or Workers KVAre the data and its consistency requirements suitable for that store?
Reach a service on another hostCloudflare TunnelWho authorizes requests, verifies the origin and restores its state?

A binding gives a Worker a configured capability and an API to a resource; it is not the end user's permission to use every operation that Worker can perform. KV is eventually consistent: a recently changed value may not immediately be visible at another location. It is therefore a different choice from a transactional database when an access decision or write must be immediately consistent. Object storage holds objects, not a drop-in replacement for a relational transaction. Other edge platforms expose comparable categories through their own APIs, with different guarantees and limits.

1. A Managed API Can Be the Application Boundary

Start with the portal's ticket list. If the managed API's operations and policies meet the requirement, both the browser and mobile app can call it directly. Static web assets are served independently; the API verifies requests and applies its data-access rules. There is no application-owned function in that data request path.

Neither a browser nor a mobile app is a security boundary. A user can change client code, call the API directly and try another object's identifier. The API must enforce the operations and rows that caller may access; hiding a button does not enforce a permission. OWASP's authorization guidance recommends checking permissions on every request and keeping decisive access checks outside the client.

Supabase is one example of a managed API over PostgreSQL. Its row-level security guidance describes combining role grants with policies that restrict which rows a caller can read or change. A publishable key is intended for client use; it is not permission to expose privileged credentials or to omit policies.

This pattern fits when the API's data model and policy language cover the product's needs. It becomes awkward when a single operation must coordinate several services, apply complex domain rules or keep an external credential out of the browser. At that point, introduce an application service because it owns a necessary responsibility, not because every application is expected to have one.

For the example portal, the browser or mobile app sends its user token to the Supabase Data API. The API validates the token; the database role and row policies decide which records are visible. A publishable key identifies the project and does not replace the user token or policy. A negative test should request a second team's record directly through the API, not merely confirm that the page hides it.

Static hosting does not automatically make every asset private. On Cloudflare Workers, matching static assets are served before Worker code by default. If a file needs an application access check, configure and test a route that invokes that check before the file is served, or keep it in protected storage. Test the actual file URL without a session as well as the normal page route.

2. Add an Edge Function When It Owns a Decision

Suppose closing a ticket must also ask the report service to generate a document. That operation crosses two services and needs application-owned coordination. An edge function can sit between the client and the managed API: it validates the command, applies the business rule and calls the required services. The managed API still owns its own access contract.

A mobile app can call the Worker's HTTPS endpoint just as a browser can. The team implements and secures the Worker's API routes; the Worker then calls the managed API or another dependency using the chosen access model.

There are two distinct ways to call the downstream API. The function can pass a verified user's access context to an API that understands it, allowing the downstream policy to act for that user. Or it can act as a privileged service, in which case the application must authorize the requested operation itself and limit what that service credential can do. A service credential is not proof that the database is applying the end user's row policy.

For example, PostgREST can verify a JWT and switch to a configured database role for a request. The deployment must choose which roles the authenticator may assume, configure token validation for its trust model and test both allowed and denied access. That is one implementation of the boundary, not a property shared by every HTTP API.

The extra function adds a deployment, a network dependency and a place where errors must be handled. Make the division explicit: which checks belong to the function, which belong to the downstream service, and what happens if either is unavailable. A failed authorization check must not turn into a privileged retry.

For that ticket operation, the Worker can call the report service with its own restricted credential after validating the user. It must not accept a caller-supplied identity header as proof of authorization. If the downstream operation times out after it may have changed state, return an outcome that supports reconciliation; do not blindly repeat a non-idempotent write. Coordinating these calls does not make them one transaction: design for a ticket update succeeding while report generation fails, and make the partial outcome visible.

3. Direct Database Access Adds a Connection Boundary

The portal's team might instead need a PostgreSQL transaction or feature its managed HTTP API does not expose. A function can use a compatible database driver for that path. This is an alternative to the managed API for the relevant operation, and it brings the connection and transaction lifecycle into the design.

Function invocations can arrive concurrently and outnumber the database connections an origin can comfortably hold. A pooling layer reuses connections and limits pressure on the origin; it does not authenticate the end user or decide what that user may read. Cloudflare Hyperdrive is one example: it pools origin connections and holds a connection for the duration of a transaction. Long transactions occupy shared capacity, so keep external calls and unrelated work outside them.

With Workers and Hyperdrive, a database driver connects using the binding supplied to the Worker; Hyperdrive manages the underlying pool to the origin. Check the driver's compatibility with the runtime, the configured pool mode and any query caching before adopting it. A cache or pool cannot supply stronger consistency than the application has designed for, and neither replaces a database access policy.

If the database enforces per-user policies, the database must receive the right, verified identity and role for each operation. PostgreSQL's SET LOCAL limits a setting to the current transaction, but it does not verify a token. Establish trusted context inside the transaction, test commit and rollback paths, and verify that one request's context cannot be reused by another. Driver, runtime and pool compatibility are part of that test.

PostgreSQL grants and row security are different controls: grants determine whether a role may perform an operation, while policies constrain applicable rows. Superusers and roles with BYPASSRLS bypass row security; table owners normally do too. Design and test the actual role used by the request rather than assuming a policy applies to every connection.

A request through a transaction pool

Return to the operations portal. A signed-in user requests a record belonging to their team. The function verifies the token's signature, issuer, audience and expiry, determines whether the user may perform the operation, and obtains a connection through the pool. The database policy needs a trustworthy identity for the same request; a connection string alone supplies only the database role, not the browser user's identity.

One possible design uses a transaction-local setting. The following is illustrative SQL, not a complete authentication or policy implementation. The application supplies the parameter from a verified identity, never directly from an unverified request header:

BEGIN;
SELECT set_config('app.user_id', $1, true);
SELECT id, status FROM tickets WHERE id = $2;
COMMIT;

The third argument scopes the setting to the transaction. An appropriate policy must read that setting and map the verified user to the permitted rows; grants and role membership must also be configured. Only the trusted service may issue queries using this context: a client able to set its own app.user_id can claim another identity. This example does not create that policy, and a role with RLS bypass is unsuitable for relying on it. On failure, roll back before releasing the connection; if rollback or connection state is uncertain, discard it instead of returning it to the pool. PostgreSQL restores the previous session setting after the transaction, so the pool must also guarantee a clean session baseline. PostgreSQL's configuration functions and SET LOCAL define the transaction scope.

Proof: run an allowed read as user A, then try the same record as user B. Repeat after a rollback and with a reused connection; B must not see A's row, and a request without identity must not inherit A's context. Test the actual driver, pool mode, database role and policy together. The example is a design option, not a complete recipe for safely impersonating a database role.

4. A Local Read Does Not Guarantee a Current Read

If the ticket workload fits an edge database's SQL and operating model, the portal can use that database instead of the relational path above. A function uses a configured binding, while the platform manages access to the data service. This can be a good fit when the service's query model, data size, consistency and recovery options match the application.

The word edge does not mean every write is local or every read immediately sees the latest write. Cloudflare D1, for example, documents a primary database and optional asynchronous read replicas. Its Sessions API provides sequential consistency within a session; without the appropriate session context, a replica can lag. That is a product-specific contract, not a guarantee to transfer to another database.

Consider the portal user changing a ticket from open to closed. The primary accepts the write; the next read reaches a replica that has not received it yet. The page can show the old status even though the write succeeded. With D1's session mechanism, a bookmark carries the required minimum database version to the subsequent read; the replica must catch up before serving it. Across separate requests, the application must carry the bookmark forward. Starting an unconstrained session does not itself guarantee that the first read sees the latest write.

Start with the user-visible requirement. After a user updates a record, must their next read show it? Can a different user briefly see an older version? Does an operation need a transaction across records? Compare those answers with the product's documented semantics and limits, then test the failure cases that matter. A convenient binding is not a substitute for that contract.

5. A Tunnel Provides a Route, Not Authorization

The portal's report generator needs a long-running process on a separate host. Other workloads may need a filesystem or specialised hardware. Keep that workload on an appropriate host and make it reachable through an edge front door; the service remains part of the application even though it runs elsewhere.

An outbound tunnel is one way to provide the route. Cloudflare Tunnel documents a connector that establishes outbound connections to its network; traffic then travels in both directions over those connections. The tunnel can avoid an inbound listener for that route, but it does not prove the host has no other exposed path.

Reachability is not authorization. Decide who may call the service, enforce that decision at the appropriate boundary and protect the path between the connector and the origin according to the network's trust assumptions. A connector can be healthy while the application behind it is unavailable; monitor both and decide what the caller sees when either fails.

The host also owns state that an edge request cannot recover by itself. Name the data that must survive host loss, where its backups live, how a restore is tested and who responds when storage or the connector fails. A tunnel changes the network path; it does not make the origin disposable.

For a deeper discussion of host storage and recovery, The Stateful Node presents a separate architecture vision. Its storage choices are not prerequisites for using a tunnel: select the origin's storage and recovery design for the workload being hosted.

What fails when the origin stops?

In the hypothetical portal, the external service generates a report. A connector on the host establishes an outbound tunnel; the request travels from the edge through that established connection to the service. The edge must authenticate and authorize the request, while the origin must accept only trusted traffic and enforce its own applicable policy. TLS and origin verification between connector and service depend on the deployment's network and configuration.

The solid arrows follow the request; the dashed arrow shows the connector initiating the tunnel. They do not imply that the edge can reach the host by every route, that the origin is encrypted end to end, or that a live connector means the report service is healthy.

FailureWhat the operator checksWhat the caller should observe
Connector disconnectedConnector state and outbound network reachabilityA bounded failure; no assumption that the origin received the request.
Connector healthy, service downService health separately from connector healthA controlled unavailable response; no retry storm.
Response lost after report creationOperation status or idempotency recordRetry only with a design that prevents a duplicate effect.
Host or data lostBackup age and last successful restore testRecovery according to the stated recovery point and time objectives, not a promise of zero data loss.

A timeout does not establish whether an operation completed. For a request with side effects, use an idempotency mechanism where the service supports one, and bound retries with backoff; otherwise surface the uncertain outcome for reconciliation. Stripe's failure analysis and Amazon's discussion of retries explain why repeated attempts can duplicate work or overload a recovering service.

The Same Operating Questions Apply to Every Path

Before choosing a pattern, write down the answers that the service documentation cannot choose for you:

  1. Authority: Which component decides whether this principal may perform this operation on this data? Which credentials or roles can bypass that decision?
  2. State and consistency: Where is the authoritative write, and what must each reader observe afterwards? Which data can be stale, and for how long is an application prepared to tolerate it?
  3. Failure: What does the caller receive when an API, database, tunnel or origin is unavailable? Which operations can be retried without repeating an effect?
  4. Recovery: What is backed up, who can restore it, and when was the restore last tested? Replication and a successful backup are not themselves a proven recovery.
  5. Evidence and change: Which signals show the path is working without exposing sensitive data? What contract and data would have to move if a service were replaced?

The answers may rule out the simplest-looking option. That is useful: a system is easier to operate when its boundaries are explicit before they are under pressure.

AI can help a team enumerate failure cases or draft policy tests for those boundaries. An engineer still has to verify the service's actual guarantees, review the tests and decide which access and recovery risks the system can accept.

The Orchestrator's Takeaway

For this example, a reasonable design is a browser and mobile app calling a team-owned Worker for ticket and report operations. The Worker can use a managed data API with user-scoped access for tickets and reach the report service through a tunnel. If the ticket workload needs capabilities the API cannot provide, direct PostgreSQL access or an edge database are alternatives, with the connection or consistency duties described above; they are not additions the design must automatically take on.

The team still has to verify who can see each ticket, what happens when report generation fails, and how the origin and data are recovered. The map shows the possible paths; those checks determine whether the selected path is ready to operate.

Read next
The engagement

AI-Augmented Architecture & Delivery

We design resilient foundations. Every system is built on strict architectural boundaries, automated quality gates, and decades of proven software design principles.

See how we work on this

Platform Engineering
Software Architecture
Infrastructure