A Request Is Not a Unit of Work

Kurt Overmier & AEGIS 6 min read

Why generative AI systems need durable jobs before they need bigger models.

Most unreliable AI products make the same architectural mistake before the model ever gets involved: they treat the HTTP request as the unit of work.

That is fine for simple web software. A user submits a form. The server validates it. The database commits. The response returns. The request can own the whole transaction because the work is short, bounded, and mostly deterministic.

Generative AI work is different. A useful AI operation might route across several models, fetch private context, call tools, wait for a human approval, retry a failed provider, write an audit trail, and reconcile cost or policy decisions after the user has already moved on. The browser request is just the doorway. The durable job is the real product boundary.

That distinction is the first primitive in The Edge That Thinks, our new field guide for building reliable generative AI systems on Cloudflare. It is also the one I would put in front of any team before they choose a model, a framework, or an agent SDK.

The Request Is a Reservation

A request should do as little as possible:

  1. authenticate the caller;
  2. validate the input;
  3. create or reserve a durable job record;
  4. return a stable job identifier;
  5. hand execution to the right background primitive.

That is the architecture that lets the rest of the system behave honestly.

If the model provider times out, the job can retry. If the user closes the tab, the job can continue. If policy changes while the work is running, the job can stop or reroute. If the same message is delivered twice, the job can deduplicate by idempotency key instead of doing the same external side effect twice.

Cloudflare's platform now has several primitives that map cleanly to this shape. Workflows are built for durable multi-step applications, including retries, state that can persist across long-running operations, and waits for external events or approvals. Queues provide asynchronous delivery and explicitly document at-least-once delivery, which means consumers must design for duplicates using idempotency keys. Durable Objects are useful when one logical actor, tenant, session, document, or conversation needs coordinated state instead of scattered database writes.

None of those primitives is "the AI architecture" by itself. The useful lesson is more portable: decide what owns progress, what owns state, what owns retries, and what owns side effects before the model starts spending tokens.

The Job Has a Lifecycle

The minimum lifecycle is usually enough:

Accepted -> Reserved -> Processing -> NeedsInput -> Processing -> Reconciled
                              |             |
                              v             v
                           Failed        Canceled

Each transition should mean something concrete.

Accepted means the request was valid enough to consider. Reserved means the system has created a durable claim on the work. Processing means a worker, workflow, or actor is doing the job. NeedsInput means the system cannot safely continue without a user, reviewer, or external event. Reconciled means outputs, cost, state, and side effects agree. Failed and Canceled are terminal outcomes, not vague logging categories.

That lifecycle seems mundane until something breaks. Then it becomes the difference between "we lost the user's work" and "the provider failed on step four, the retry policy exhausted, no external side effect was committed, and the user can resume from a known state."

AI systems need that boring precision because model calls are expensive, variable, and often attached to irreversible actions. The same principle underlies our audit-trail design for autonomous agents and production governance work. Sending an email, updating a CRM record, publishing an article, or charging a customer cannot be hidden inside a best-effort request handler.

Route Before You Reason

Once work is represented as a durable job, routing becomes a system decision rather than a prompt trick. It connects directly to our earlier work on cost-aware routing and tiered execution and confidence-boundary routing.

Some jobs do not need a frontier model. Some need retrieval before reasoning. Some need a cheap classifier first. Some need a deterministic policy check before any model sees private context. Some need a human approval step. Some need to stop immediately because the requested action is outside the user's authority.

The routing ladder in the guide is intentionally simple:

rules -> cache -> small model -> specialized model -> frontier model -> human

Start with the cheapest proven capability. Escalate only when evidence, capability, risk, or policy requires it.

This is where the edge matters. Cloudflare gives builders a place to put routing, identity, state, queues, workflow steps, model gateway policy, and observability close to the application boundary. That does not remove the need for product judgment, but it does make the right shape cheaper to implement.

The mistake is thinking the model is the control plane. It is not. The system is the control plane. The model is one capability the system can call. That is the same selection-over-generation pattern we have seen across convergent AI dispatch systems.

A Small Example

Imagine a support product that drafts a refund recommendation.

The weak version handles everything in one request:

POST /refund-draft
  fetch customer
  fetch order
  call model
  maybe call payment API
  return result

That is brittle. If the browser disconnects, the model stalls, the payment API duplicates a side effect, or the policy rules change, there is no clear owner of truth.

The durable version splits the concern:

POST /refund-draft
  authenticate
  validate
  create job refund_draft:{idempotency_key}
  enqueue or start workflow
  return 202 + job_id

job refund_draft
  load customer and order context
  evaluate deterministic policy
  route model only if needed
  require approval above threshold
  commit external side effects once
  reconcile result, cost, trace, and audit log

That second version is less dramatic in a demo. It is much better in production.

The Production Test

Before shipping an AI workflow, ask five questions:

  1. If the user closes the browser, who owns the work?
  2. If the model provider times out, what retries and what does not?
  3. If the same message is delivered twice, which side effects are idempotent?
  4. If the job needs human input, where does it wait?
  5. If the output is challenged later, what trace explains the decision?

If those answers are vague, the architecture is not ready. The fix is usually not a bigger model. It is a clearer unit of work.

That is the spine of The Edge That Thinks: reliable AI systems are built from portable primitives first and platform services second. Cloudflare happens to make many of those primitives available at the edge. The more important lesson is that the primitives are the product.

Read the free field guide: https://stackbilder.com/resources/the-edge-that-thinks

Source Notes

Written by Kurt Overmier & AEGIS. Published on The Roundtable.
Learn more at stackbilder.com →