Composable AI Architecture

Last updated: 2025-08-19
The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services.

Introduction

The AI market is witnessing a rapid evolution, propelled by the swift pace of technological advancement. With breakthroughs occurring frequently, staying up-to-date with the latest innovations is imperative for organizations aiming to remain competitive. Short iteration cycles and agility have become indispensable in this landscape, allowing businesses to swiftly adopt and leverage the newest advancements in AI technology.

In this dynamic environment, the concept of composability, data portability, and standard APIs emerges as crucial factors in navigating the complexities of the AI ecosystem:

๐Ÿ”ง Composability

The ability to assemble various AI components into tailored solutions, enabling organizations to mix and match different technologies to suit their specific needs.

๐Ÿ”„ Data Portability

Plays a pivotal role in facilitating seamless data exchange between different AI systems and platforms, ensuring interoperability and preventing data silos.

๐Ÿ”Œ Standard APIs

Serve as the linchpin for integrating diverse AI components, enabling seamless communication and collaboration between disparate systems.

The significance of composability, data portability, and standard APIs becomes particularly pronounced in mitigating vendor lock-in and fostering flexibility. By embracing these principles, organizations can sidestep dependency on single vendors and instead opt for a best-in-class approach, selecting the most suitable solutions for their unique requirements. Overall, these principles pave the way for a more agile, adaptable, and future-proof AI ecosystem.

Cloudflare's AI platform has been designed with these principles in mind. The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services.

Composable AI Infrastructure

๐Ÿ“Š Figure 1: Composable AI Architecture

The composable AI architecture enables flexible integration of various AI components and services

The composable AI infrastructure consists of four main layers that work together to create a flexible and scalable AI application architecture:

1. Compute Layer

๐Ÿ’ป

Core Application Logic

The compute layer is the core of the application. All business logic, as well as use of other components, is defined here. The compute layer interacts with other services such as inference services, vector search, databases and data storage.

Key Features:

  • Serverless solutions like Cloudflare Workers offer fast iteration and automatic scaling
  • Developers can focus on the use case instead of infrastructure management
  • Support for standard interfaces such as HTTP or TCP
  • Workers' runtime supports both fetch() API and connect() API

2. Inference Services

๐Ÿง 

AI Capabilities

AI inference is responsible for the AI-capabilities of the application. Operational models vary between self-hosting models or consuming Inference-as-a-service providers.

Self-Hosted Models

  • Full control over model deployment
  • Custom optimization possibilities
  • Infrastructure management required

Inference-as-a-Service

  • Workers AI provides managed inference
  • REST APIs for easy integration
  • Platform-specific bindings for simplified development

Example: Using Workers AI

// Using platform-specific bindings
const response = await env.AI.run(
  '@cf/meta/llama-2-7b-chat-int8',
  {
    prompt: "What is AI composability?"
  }
);

4. Data & Storage

๐Ÿ’พ

Persistent State Management

Databases and data storage add state to AI applications. User management, session storage and persisting data are common requirements for AI applications.

D1 - SQLite Database

  • Relational data storage
  • User management
  • Session storage
  • Structured queries

R2 - Object Storage

  • Large file storage
  • Model weights
  • Training data
  • Media files

KV - Key-Value Store

  • Fast cache layer
  • Configuration data
  • Session tokens
  • Temporary data

Durable Objects

  • Stateful coordination
  • Real-time collaboration
  • WebSocket connections
  • Consistent state

REST APIs make interacting with these services from any service/client easy to implement. Using platform-specific integrations such as Bindings for interaction between Workers and data services enables simplified development as complexity such as authentication is abstracted away.

Integration Patterns

๐Ÿ”— API-First Integration

Use REST APIs for cross-platform compatibility and maximum flexibility

fetch('https://api.cloudflare.com/...')

โšก Platform Bindings

Leverage native bindings for simplified authentication and lower latency

env.AI.run(...)

๐ŸŒ Hybrid Approach

Combine Cloudflare services with external providers for best-of-breed solutions

๐Ÿ“ฆ Microservices

Build modular AI services that can be composed into larger applications

Best Practices

โœ… Design for Portability

Use standard interfaces and avoid vendor-specific features where possible to maintain flexibility

โœ… Implement Abstraction Layers

Create abstraction layers between your business logic and infrastructure services

โœ… Monitor Performance

Implement comprehensive observability across all components of your AI stack

โœ… Plan for Scale

Design your architecture to handle both vertical and horizontal scaling requirements

โœ… Secure by Default

Implement security at every layer, from API authentication to data encryption

Next Steps

Build Your First AI App

Get started with Workers AI and build your first AI-powered application

Get Started โ†’

Explore RAG Patterns

Learn how to implement Retrieval-Augmented Generation for context-aware AI

Learn More โ†’