Technical document

Boundary Design When Using Cloudflare Workers Around RAG

When placing Cloudflare Workers around RAG or APIs, we organize how to draw boundaries for edge processing, authentication, caching, and long-running processes.
Edge / RAG~10 minPublication Date September 22, 2026Update date September 22, 2026
Boundary Design When Using Cloudflare Workers Around RAG

Summary

Key points of this document

  • Where are the design challenges?
  • How to draw the boundaries
  • Details that matter in implementation

Overview

Cloudflare Workers are suitable for lightweight edge processing, but designing RAG to perform everything at the edge is not always correct. It's necessary to identify the boundaries of processing time and data access. When placing Cloudflare Workers around RAG, the design focus is on what to entrust to fast edge processing and where to offload heavy generation processes.

Where are the design challenges?

In RAG, search, re-ranking, and generation take time. Attempting to process everything at the edge can run into constraints regarding execution time, connection destinations, sensitive information, and streaming.

While Cloudflare Workers are strong for delivery and lightweight APIs, they are not suitable for heavy database processing or long-running jobs. Additionally, caching responses related to user-specific permissions can lead to information exposure.

RAG includes document search, prompt construction, generation, and log storage, so it may not be suitable to complete everything at the edge. While the speed of Cloudflare Workers is attractive, execution time, connection destinations, sensitive information, and log handling must be considered.

How to draw the boundaries

Workers are used for authentication token validation assistance, request normalization, caching static information, and routing to the backend. RAG's search and generation are placed on Hono or a separate backend, returning via streaming as needed.

In the design, the edge is used as an entry point, handling authentication, rate limiting, caching, and request normalization. Search and generation are passed to a backend closer to the database or vector index, and Workers handle correlation IDs and light formatting of results.

Details that matter in implementation

On the edge side, assign a request ID, set a short timeout, and convert backend errors to a unified format. Cache targets are limited to public documents and model lists, and user-specific search results are not stored.

Even when using Hono on Workers, keep the RAG core service interface separate. On the edge side, determine user context, request size, cacheability, and trace_id, and explicitly pass them to the backend.

  • Do not directly handle long-running generation processes within Workers; consider boundaries for streaming or jobification.
  • Caching should be limited to public information and low-risk search aids, and individual responses should not be inadvertently shared.
  • Log the same trace_id in both the edge and the backend.

Observe how it breaks

During validation, check for backend delays, authentication failures, cache misuse, streaming interruptions, and regional differences. Logs should use the same request ID across the edge and backend for traceability.

During validation, check for edge timeouts, backend delays, rate limiting, and cache mis-sharing. Special attention is paid to ensuring that responses for authenticated users are not mixed with those for other users.

Discarded options and tradeoffs

Moving processing to the edge speeds up responses, but state management and debugging become more complex. Since RAG quality improvements are often done on the backend, keeping the edge thin can sometimes be easier to operate.

Moving to the edge speeds up initial responses, but stateful processing and long-running processes become difficult. Moving to the backend makes control easier, but increases latency. In RAG, it's crucial to decide between a lightweight entry point and observability of core processing.

Decision criteria to keep in mind

Cloudflare Workers are not magic for speeding up RAG. Separating lightweight processes that should be placed at the edge from heavy processes handled by the backend leads to a stable configuration.

Cloudflare Workers are not meant to be the entire location for RAG; their strength comes from being used as an entry point boundary. The role should be determined not only by speed but also by considering the location of data, sensitive information, and logs.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list