All posts
AI Infrastructure
Modal Team
18 min read

Best Serverless Platforms for Hosting RAG Application Backends in 2026

Retrieval Augmented Generation (RAG) application backends commonly handle document retrieval, optional embedding and vector-search workflows, and LLM generation, often under variable traffic. Serverless platforms can offer automatic scaling, consumption-based billing options, and reduced infrastructure management. For teams building RAG applications in 2026, selecting the right AI infrastructure can materially affect responsiveness, operating efficiency, and the ability to scale demanding retrieval and generation workloads.

This guide examines seven serverless platforms suited for RAG backend hosting, starting with Modal, an AI infrastructure platform built for serverless CPU and GPU workloads, code-defined development, large-scale parallel processing, inference, training, and secure sandboxed execution.

Modal Sandboxes in production

Key Takeaways

  • AI-specialized infrastructure is a strong fit for demanding RAG workloads: Modal combines native serverless GPU compute, per-second GPU pricing, scale-to-zero infrastructure, CPU compute, and code-defined infrastructure through Python, TypeScript, and Go SDKs. Google Cloud Run also provides generally available serverless GPU instances, and Azure Functions can access serverless GPUs through Azure Container Apps.
  • Cold start performance is workload-specific: Runtime architecture, dependencies, container provisioning, model loading, cache state, and snapshotting all affect cold-start latency. Cloudflare's 2025 Python benchmark illustrates how dependency sets can affect startup behavior. Modal is engineered for fast cold starts and faster feedback loops, with an optimized filesystem that helps containers come online quickly without letting large images slow startup down. Memory Snapshots can further reduce initialization overhead for suitable workloads.
  • Execution limits vary by invocation model: Supabase paid Edge Functions cap worker wall-clock time at 400 seconds, eligible Vercel Node.js and Python Functions can run up to 30 minutes, Cloudflare HTTP Workers have no hard wall-clock duration limit but do enforce CPU limits, eligible AWS Lambda Managed Instance asynchronous invocations can run up to 90 minutes, and Modal Functions can run for up to 24 hours.
  • Vector database placement impacts retrieval latency: Supabase combines Edge Functions with Postgres and pgvector. Functions run near the requesting user by default, and database-intensive functions can be invoked in the database region to reduce round trips. Modal can connect to external vector databases while also providing persistent storage and distributed state primitives for appropriate RAG architectures.
  • Language support is only one part of ML framework compatibility: Native-extension support, memory, CPU and GPU access, threading, package availability, and runtime constraints also determine whether frameworks such as PyTorch and Transformers are practical on a serverless platform. Cloudflare's Python runtime documentation illustrates how an edge Python runtime can differ from a conventional Linux ML environment. Modal provides container-based CPU and GPU compute designed for AI workloads.

1. Modal: AI-Native Serverless for RAG Backends

Modal delivers AI infrastructure engineered for workloads such as RAG, inference, training, batch processing, and agentic execution. Modal says it serves thousands of customers and combines CPU compute, native GPU compute, per-second GPU pricing, and scale-to-zero infrastructure with code-defined development through Python, TypeScript, and Go SDKs.

Modal's AI-Optimized Infrastructure

Modal built substantial parts of its core serverless infrastructure, including its own gVisor-based runtime, filesystem, and job scheduler, to support demanding AI workloads. This deep integration enables:

  • Native CPU and GPU support: Modal supports CPU execution and a broad GPU catalog, including B300, B200, H200, H100, RTX PRO 6000, A100, L40S, A10, L4, and T4, for embedding generation, reranking, local LLM inference, fine-tuning, and other accelerated workloads. The GPU guide documents current GPU options.
  • Fast cold starts: Engineered for fast cold starts and faster feedback loops, with an optimized filesystem that helps containers come online quickly without letting large images slow startup down. Memory Snapshots can reduce initialization overhead for workloads that benefit from restoring initialized memory state. Modal's GPU inference engineering analysis describes infrastructure techniques for serverless GPU workloads.
  • 24-hour maximum execution time: Modal Functions can be configured to run for up to 24 hours, supporting long-running batch document processing, embedding pipelines, indexing jobs, and fine-tuning workflows.
  • Configurable compute resources: Modal lets developers configure container memory and set CPU and GPU resources for workloads ranging from retrieval services to memory-intensive model loading and accelerated inference.

Developer Experience with Modal

Modal provides a code-first SDK experience through Python, TypeScript, and Go SDKs, while Modal handles containerization, resource provisioning, and autoscaling. Modal Sandboxes can run workloads in whatever programming language or runtime the environment contains, so sandboxed execution can use the language required by the workload.

Key platform primitives for RAG backends include:

  • Volumes: Persist model weights, documents, cached assets, and application-managed file-based indices across function invocations.
  • Queues: Provide distributed FIFO data flow between active Modal workloads. For asynchronous document-processing jobs, Modal separately documents a job-processing pattern built around Function.spawn() and FunctionCall.
  • Dynamic batching: Enable @modal.batched so Modal can accumulate incoming inference requests into dynamically sized batches for higher throughput.
  • Dicts: Provide distributed key-value state for application coordination and RAG workflow state.

Modal for Inference, Training, and Agentic RAG

Modal Inference provides infrastructure for serving custom and open models with automated scaling and production observability. For teams fine-tuning embedding models, rerankers, or generation models, Modal Training supports GPU training workflows, including multi-node configurations and high-bandwidth networking for distributed acceleration. Modal's multi-node cluster documentation covers distributed training configurations.

Modal Sandboxes provide isolated execution environments for systems that run untrusted or model-generated code. In a RAG architecture, Sandboxes are particularly relevant when an agent generates code, executes shells, manipulates files, launches application servers, or iterates on code produced from retrieved context. RAG systems that only retrieve context and generate responses do not inherently require sandboxed execution. Modal Sandboxes support SDK operations through Python, Go, and JavaScript or TypeScript, while code inside a Sandbox can use the runtime or language required by the workload.

Best For: Teams building sophisticated RAG systems that need serverless CPU and GPU compute, code-defined infrastructure, long-running batch processing, local model serving, fine-tuning, or isolated execution for agentic workflows.

2. Cloudflare Workers: Edge Serverless for Global RAG

Cloudflare Workers provides edge computing across a network that Cloudflare says spans more than 335 cities in 125 countries, supporting globally distributed retrieval and orchestration workloads.

Edge Execution for RAG

By default, Workers execute in the Cloudflare data center closest to the incoming request. Startup behavior depends on the runtime, dependencies, and workload. Cloudflare's December 2025 Python Workers benchmark illustrates that dependency sets can materially affect startup behavior.

Key Capabilities

  • Isolate-based runtime with startup behavior dependent on the language runtime and dependency set.
  • 335+ cities across 125 countries in Cloudflare's published network footprint.
  • KV storage and Durable Objects for caching and state management.
  • Workers AI for managed inference on Cloudflare infrastructure.

Runtime Model

Cloudflare Workers supports JavaScript and TypeScript and provides a Python runtime that is currently in open beta. Python Workers execute with Pyodide, a CPython implementation compiled to WebAssembly. The environment differs from a conventional Linux ML container, so package compatibility, native-extensions, memory, threading, and compute characteristics shape which RAG components fit the Workers runtime model. Workers use 128 MB of memory per isolate. Paid Workers can be configured for up to five minutes of CPU time, while HTTP Workers do not have a hard wall-clock duration limit as long as the client remains connected.

Best For: Teams using Cloudflare's edge runtime for globally distributed retrieval, orchestration, caching, and managed inference workloads that fit the Workers runtime model.

3. Supabase Edge Functions: Postgres-Backed Serverless for RAG

Supabase Edge Functions use a Deno-compatible, TypeScript-first runtime and pair with Supabase Postgres for RAG applications using pgvector for vector storage.

Database and Functions

Supabase Edge Functions run close to the requesting user by default. For database-intensive RAG operations, teams can invoke functions in the same region as the Supabase Postgres database to reduce database round trips. Supabase Postgres supports the pgvector extension for embedding storage and vector similarity search without requiring a separate managed vector database.

Key Features

  • Supabase Postgres with pgvector for embedding storage and vector similarity search.
  • Deno-compatible runtime with TypeScript-first development.
  • Integrated authentication with Supabase Auth.
  • Real-time subscriptions for live data updates.

Extending Supabase for RAG

Supabase combines database, authentication, storage, and Edge Functions within the same platform ecosystem. Supabase also provides a built-in AI inference API for supported models, including text embedding generation. This managed inference interface is distinct from raw user-controlled GPU infrastructure.

Best For: Teams using Supabase Postgres with pgvector that want database, authentication, storage, and serverless application functions within the Supabase ecosystem.

4. AWS Lambda: Serverless for AWS RAG Backends

AWS Lambda is a serverless compute service with integrations across AWS services relevant to RAG applications.

AWS Services for RAG

Lambda integrates with Amazon Bedrock for managed LLM inference, S3 for document storage, and DynamoDB for metadata. Teams building RAG on AWS can use these managed services alongside Lambda functions.

Key Specifications

  • Execution time depends on invocation mode: Synchronous Lambda invocations retain a 15-minute maximum, while eligible asynchronous and event-source-mapping invocations on Lambda Managed Instances support up to 90 minutes.
  • Memory depends on the execution model: Standard Lambda function memory is configurable up to 10,240 MB, while Lambda Managed Instances support up to 32 GB and 16 vCPUs.
  • Provisioned Concurrency can keep execution environments initialized to manage cold starts.
  • Conventional Lambda functions use CPU execution: CPU-based model inference can run inside Lambda, while GPU-dependent workloads generally use other AWS AI or GPU-capable compute services.

Lambda for RAG Workloads

Lambda can handle event-driven retrieval, orchestration, document processing, API operations, and integrations with managed AWS AI services. Longer-running or GPU-dependent stages can use other AWS compute services while Lambda coordinates the surrounding workflow.

Best For: Teams using AWS services such as Bedrock, S3 Vectors, S3, DynamoDB, and other managed components for RAG architectures.

5. Google Cloud Run: Container Serverless for RAG

Google Cloud Run offers container-based serverless deployment with separate service and job execution models and generally available GPU support. Its general service memory configuration supports up to 32 GiB, while GPU configurations have separate resource requirements.

Container Deployment for RAG

Cloud Run accepts Docker and OCI container images that satisfy its container runtime contract, allowing teams to package compatible languages, runtimes, ML libraries, and model dependencies in a conventional container environment.

Key Specifications

  • 60-minute maximum service request timeout for Cloud Run services, while Cloud Run Job tasks have separate limits: non-GPU tasks can run for up to 168 hours, while GPU tasks have a one-hour maximum.
  • Memory varies by configuration: The general Cloud Run service memory configuration supports up to 32 GiB, while GPU service configurations have separate requirements, including at least 80 GiB for NVIDIA RTX PRO 6000 Blackwell and at least 16 GiB for L4.
  • Up to 1,000 concurrent requests per instance under Cloud Run's current maximum concurrent requests setting.
  • Generally available GPU support: NVIDIA L4 became generally available in June 2025, and Cloud Run release notes document RTX PRO 6000 Blackwell as generally available in April 2026.

GCP AI Services

Cloud Run integrates with Vertex AI for model serving and Cloud Storage for document management. Teams on GCP can combine Cloud Run compute with managed AI and data services in a RAG architecture.

Best For: Teams using containerized RAG components, separate serverless service and job models, supported GPU configurations, or the broader Google Cloud ecosystem.

6. Azure Functions: Serverless for Enterprise RAG Applications

Azure Functions provides serverless compute with virtual network integration, Durable Functions for orchestration, and integration with Azure AI Search through Azure SDKs and REST APIs.

Azure Functions for RAG

Azure Functions supports private networking patterns, stateful orchestration, configurable hosting options, and integration with Microsoft cloud services.

Key Capabilities

  • Virtual network integration for private connectivity.
  • Durable Functions for complex, stateful workflow orchestration.
  • Multiple language support including Python, C#, and JavaScript.
  • Premium and Dedicated hosting tiers for configurable enterprise hosting.
  • Serverless GPU access through Azure Container Apps, with Microsoft documenting NVIDIA T4 and A100 options that can scale to zero.

AI and Data Services

Azure AI Search provides managed vector search and hybrid retrieval capabilities. Combined with Azure OpenAI Service, Azure Functions can coordinate RAG applications within the Azure ecosystem.

Best For: Organizations with existing Azure investments using Azure networking, orchestration, search, identity, and AI services for enterprise RAG applications.

7. Vercel Functions: Serverless for RAG Web Applications

Vercel Functions provides serverless application compute within Vercel's web deployment platform and the Next.js ecosystem, including deployment and caching options for RAG-powered interfaces.

RAG Interfaces and Backends

Vercel supports full-stack Next.js applications with API routes, server components, caching, preview deployments, and Git-based deployment workflows.

Key Capabilities

  • Native Next.js integration with API routes and server components.
  • Vercel Functions with Fluid compute for the current serverless execution model. Legacy Edge Functions are deprecated for new projects.
  • Incremental Static Regeneration for cacheable page-generation workflows and CDN caching for appropriate function or API responses.
  • Preview deployments for testing RAG changes.

Developer Workflow for AI Apps

Vercel provides monorepo support and Git-based deployments for application development workflows. Vercel Functions using Fluid compute default to a five-minute duration, while eligible Node.js and Python Functions on Pro and Enterprise can opt into durations up to 30 minutes. Vercel states that durations above 800 seconds are currently beta and require Fluid compute. GPU-heavy RAG inference can use an external GPU or model provider while Vercel handles the application and delivery layer.

Best For: Teams building RAG-powered web applications with Next.js that use Vercel for the web deployment layer and separate model or GPU infrastructure for compute-intensive stages.

Why Modal Stands Out for RAG Application Backends

Among these seven platforms, Modal is differentiated by an AI infrastructure model that combines code-defined serverless compute, CPUs and GPUs, long-running functions, large-scale parallel processing, model inference, training, and isolated Sandboxes in one platform. Modal brings these capabilities together in an AI-specialized workflow for demanding RAG stages.

AI-Specialized Serverless Compute

RAG applications can benefit from direct control over the compute that runs embeddings, rerankers, document processors, and generation models. Modal combines CPU compute, a broad modern GPU catalog, per-second GPU pricing, and scale-to-zero infrastructure in one AI-specialized platform. Cloud Run also provides raw serverless GPU instances, Azure Functions can access serverless GPUs through Azure Container Apps, and Cloudflare Workers AI provides managed serverless GPU inference. Modal's differentiation is the integration of serverless compute, inference, training, batch processing, and code-defined infrastructure in an AI-specialized workflow.

Code-First AI Development

Modal supports code-defined infrastructure through Python, TypeScript, and Go SDKs. Developers can define workloads in application code, including Python functions, while Modal handles containerization, provisioning, and autoscaling. For Sandboxes, the code running inside the isolated environment can use whichever programming language or runtime the workload requires.

Fast Cold Starts and Feedback Loops

Modal is engineered for fast cold starts and faster feedback loops, with an optimized filesystem that helps containers come online quickly without letting large images slow startup down. Memory Snapshots provide an additional mechanism for reducing repeated initialization work in suitable applications.

Execution Time for Real Workloads

RAG document processing often involves ingesting, parsing, chunking, embedding, reranking, indexing, and model processing across large document corpora. Modal's 24-hour Function execution limit provides substantial continuous execution time for these workflows and reduces the need to split long batch jobs solely to fit short function timeouts. By comparison, Lambda Managed Instance asynchronous and event-source-mapping invocations can now run for up to 90 minutes.

Enterprise-Grade Security

For teams with compliance requirements, Modal says it has completed a SOC 2 Type 2 audit and uses gVisor-based compute isolation. Modal supports HIPAA-compliant workloads on Enterprise plans via a BAA. Role-based access controls and audit logs support enterprise governance requirements.

For agentic RAG systems that execute model-generated or otherwise untrusted code, Modal Sandboxes provide isolated execution environments designed for running that code remotely rather than inside a normal application or developer environment. The Sandbox runtime is separate from Modal Functions and provides a raw-container interface for execution-heavy workflows.

Integrated Primitives for RAG Architectures

Modal's platform primitives provide building blocks for production RAG systems: Volumes for persistent filesystem storage, Queues for distributed FIFO data flow, job processing for asynchronous task fan-out, and Dicts for distributed key-value state. Modal also publishes a self-contained RAG example that stores application state and embeddings in Modal primitives. Modal compute can also connect to dedicated vector databases such as Postgres when that architecture is preferred.

This combination gives teams a unified platform for serving the online RAG path, running batch ingestion, using CPUs or GPUs as each stage requires, and isolating code execution when agentic workflows need it.

Frequently Asked Questions

  • RAG applications combine a retrieval stage with LLM generation to produce responses grounded in selected source content. Retrieval can be lexical, vector-based, or hybrid, as well as other application-specific methods. Serverless platforms can suit RAG backends because demand may be variable or bursty and automatic scaling can reduce capacity-planning overhead. Scale-to-zero and consumption-based modes can reduce idle compute costs, although total billing can still include storage, requests, networking, plan fees, or provisioned capacity depending on the platform.

  • GPU execution models differ across these services. Modal provides user-selectable serverless GPU compute with CPU execution, per-second pricing, and scale-to-zero infrastructure. Google Cloud Run provides generally available raw serverless GPU instances. Azure Functions can use serverless NVIDIA T4 and A100 GPUs through Azure Container Apps. Cloudflare provides managed GPU inference through Workers AI. Supabase exposes a built-in AI inference API for supported models. AWS Lambda can host lightweight CPU inference and uses separate AWS AI or GPU-capable services for GPU-dependent workloads. Vercel Functions can connect to an external GPU or model provider for GPU-heavy inference. For teams that want direct serverless GPU selection, batch processing, inference, and training within one AI-focused platform, Modal offers the most integrated option in this comparison.

  • Cold-start behavior depends on runtime architecture, dependencies, image size, model initialization, cache state, and workload design. Modal is engineered for fast cold starts and faster feedback loops, with an optimized filesystem that helps containers come online quickly without letting large images slow startup down. Memory Snapshots can reduce repeated initialization work for suitable workloads. AWS Lambda offers Provisioned Concurrency for initialized execution environments. Cloudflare Workers uses an isolate-based runtime, with startup behavior dependent on the runtime and dependency set. Other serverless platforms provide their own startup-management mechanisms within their respective execution models.

  • Key security considerations include data encryption in transit and at rest, tenant isolation, compliance scope, access controls, auditability, secret management, and network boundaries. Modal says it has completed a SOC 2 Type 2 audit and uses gVisor-based container isolation. Modal supports HIPAA-compliant workloads on Enterprise plans via a BAA. For agentic RAG systems that execute untrusted or model-generated code, Modal Sandboxes add an isolated execution layer between generated code and the surrounding application environment.

  • Yes. Major serverless platforms can connect to external vector databases over network APIs. Supabase combines Edge Functions with Supabase Postgres and pgvector; functions run near the requester by default, and teams can invoke them in the database region for database-intensive work. On Modal, teams can persist application-managed indices and model assets in Volumes, use Modal primitives for self-contained RAG designs, or connect Modal compute to an external vector database. Modal's documented RAG example uses Modal primitives, and teams can also connect dedicated databases such as Postgres when that architecture is preferred.

Explore Modal

Build your RAG backend on Modal.

$30 in free compute to get started.