← Back to Case Studies
Jul 2026Associate Director, Cloud Architecture & AI

Edge-Native Digital Twin Portfolio Engine: Cloudflare Workers AI & D1 RAG

Building a secure, serverless RAG platform with zero external trackers and sub-second edge builds.

#Agentic AI#Cloudflare Pages#Workers AI#Vector RAG#D1 SQL#case-study

β€œYour portfolio shouldn’t just list your accomplishments. If you’re an AI and Infrastructure Architect, your portfolio is the accomplishment.”

Executive Summary

To showcase production-grade Agentic AI and edge-native infrastructure capabilities, I designed and built VirtualSach.in β€” an Edge-Native Cognitive Platform.

Instead of building a simple static page or deploying complex virtual instances that incur idle compute bills, I architected a serverless system running entirely inside the Cloudflare Free Tier. The engine incorporates a vector-backed RAG Digital Twin chat, an anonymous bidirectional recruiter channel routing directly to Telegram, dynamic architecture simulations, and self-hosted, privacy-first telemetry.

The platform handles real-time compute loops with zero cold starts, sub-second build times, and zero maintenance overhead.


The Challenge

Most engineering portfolios are built using templates that fail to demonstrate actual system design expertise. For a senior cloud technocrat, the challenge was to design a platform satisfying four production constraints:

  1. Dynamic Edge Execution: RAG chat and interactive tools must run on edge endpoints without central server dependencies.
  2. Zero Maintenance & Cost: Total infrastructure cost must fit inside serverless free-tier limits ($0/month) while maintaining enterprise-level availability.
  3. Data Privacy compliance: Telemetry must be fully self-hosted. Zero Google Analytics or third-party cookies.
  4. Resiliency: Outbound AI connections must survive rate limits or downstream provider failures.

The Architecture

The system compiles via Astro v5 with Server-Side Rendering (SSR) enabled for dynamic edge endpoints.

                                [ Cloudflare Edge Network ]
                                             β”‚
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β–Ό                          β–Ό                          β–Ό
        [ Pages SSR Engine ]          [ Workers KV ]             [ D1 SQLite DB ]
        (Llama 3.1 Instruct,          (Cache-aside,              (Guestbook, NOC,
        Whisper Audio API)            availability state)        Message queues)
                  β”‚
                  β–Ό
         [ Vectorize Index ]
         (RAG Semantic Search)

Technology Stack

  • Serverless Compute: Cloudflare Pages (Astro v5 SSR)
  • Edge Storage: Cloudflare D1 SQL Database (Relational state & logs)
  • Fast Storage: Cloudflare Workers KV (Cache-aside & availability configurations)
  • Cognitive Engines: Workers AI (Whisper for audio, Llama 3.1 8B Instruct for text, BGE Small for embeddings)
  • AI Gateway: Cloudflare AI Gateway (Semantic caching, usage analytics)
  • Vector Database: Cloudflare Vectorize (Cosine-similarity matching)

Technical Deep Dive

  • Embedding Pipeline: User prompts are converted to 384-dimensional vector slices using @cf/baai/bge-small-en-v1.5.
  • Search Logic: The engine queries Cloudflare Vectorize to pull matching resume case studies. If bindings are absent (local dev), the platform falls back to title/tag token matching to preserve compilation sanity.
  • SSE Stream: The bot returns text streams via Server-Sent Events (event-stream) alongside ragContext JSON payloads. The UI parses the context to render clickable source pills below bot messages.

2. Stateful Circuit Breaker FSM

To prevent AI query outages under rate-limits:

  • The backend checks primary Llama 3.1 model availability.
  • A failure counter automatically trips the circuit to OPEN state.
  • During OPEN cycles, calls fall back to Llama 3 or TinyLlama endpoints, maintaining 100% availability.
// /src/lib/circuitBreaker.ts
// Simplistic circuit state machine fallback logic
export async function runWithFallback(
  env: any,
  runQuery: (model: string) => Promise<any>,
) {
  const cbState = (await env.KV.get('circuit_breaker_state')) || 'CLOSED';

  if (cbState === 'OPEN') {
    // Failover model path
    return runQuery('@cf/meta/llama-3-8b-instruct');
  }

  try {
    return await runQuery('@cf/meta/llama-3.1-8b-instruct-fast');
  } catch (err) {
    // Trip circuit on error threshold
    await env.KV.put('circuit_breaker_state', 'OPEN', { expirationTtl: 300 });
    return runQuery('@cf/meta/llama-3-8b-instruct');
  }
}

3. Bidirectional Telegram Messaging Gateway

  • Recruiters initiate anonymous chats creating a session UUID and a human-friendly ticket code (e.g. S-2E4A).
  • The API creates a matching, dedicated forum topic inside Sachin’s private Telegram Supergroup.
  • Webhooks route Sachin’s Telegram replies back to D1 tables, while the client uses a lightweight 5-second polling system to fetch messages without long-polling battery drain.

Verification & Results

  • Build Velocity: Deploys and compiles in $<200\text{ms}$ client-side, with Vite bundling complete in $<1\text{s}$.
  • Edge Latency: Average TTFB (Time to First Byte) under $40\text{ms}$ globally via Cloudflare CDN caching.
  • Resource Footprint: 100% serverless. Zero running VMs or databases to manage.
  • Reliability: Pre-push Husky hooks execute credentials scan, full SSR compile, and run 80 unit tests (Vitest) before commits are accepted.

Key Takeaway

You do not need a multi-million dollar cloud budget to build high-availability, secure cognitive products. By utilizing edge-native serverless architecture and designing fallback paths, you can deliver premium digital experiences with zero running costs and zero system maintenance.


Architecture and decisions: mine. Debugging sessions at odd hours: mine. AI assistance: structure, syntax, first draft. β€” Sachin

⚑ Theme Adaptive Shift
Switching layouts matching domain reading affinity...