Skip to content

Messenger Tech Stack: Core Services & Primitives

CF Messenger is built entirely on the Cloudflare ecosystem. Instead of relying on traditional servers in one or two locations, it uses a “serverless-first” architecture that lives across the globe simultaneously.

[!TIP] Each service is chosen for what it does best: Workers for logic, Durable Objects for state, KV for caching. The result is minimal glue code and maximum operational simplicity.

ComponentTechnologyPrimary Role
ComputeCloudflare WorkersServerless logic & request routing
StateDurable ObjectsStrongly consistent real-time storage
SessionCloudflare KVGlobally distributed session store
AIWorkers AIServerless GPU-based inference (Llama 3.2)
SecurityCloudflare WAF / TurnstileLayer 7 protection & bot verification
AnalyticsAnalytics EngineHigh-cardinality observability

Beyond individual tools, Cloudflare provides structural benefits that define the CF Messenger experience:

  • Zero Egress Fees: Unlike many cloud providers, Cloudflare does not charge for data transferred out of its network (e.g., from R2 storage). This removes a major cost barrier for data-intensive applications.
  • Global Network Distribution: Your code executes in 330+ cities across 120 countries. This places compute power milliseconds away from users, regardless of their location.
  • Integrated Security: Security is a core component of the network, not an add-on. Protection against DDoS attacks and malicious bot traffic is baked into the infrastructure. The current POC leverages Cloudflare’s Free WAF tier to provide essential baseline security against common web threats.
  • Cohesive Developer Experience: A single platform manages databases, object storage, AI models, and backend logic, simplifying the development lifecycle.

  • The Concept: The application’s core logic and routing layer.
  • Implementation: Replaces traditional web servers by handling every request and coordinating data flow across the system.
  • The Concept: A globally distributed, high-speed data storage for quick lookups.
  • Implementation: Manages user sessions (CF_MESSENGER_SESSIONS) with a 20-minute TTL, ensuring session state is available globally with minimal latency.
  • The Concept: Specialised containers for stateful data that require strict consistency.
  • Implementation:
    • ChatRoom: Ensures all participants in a conversation receive the same updates simultaneously.
    • PresenceRoom: Coordinates real-time status updates (Online/Away) across the global network.
  • The Concept: A high-cardinality logging and event tracking system.
  • Implementation: Records critical application events, such as logins and AI triggers, providing deep visibility into system performance.
  • The Concept: Serverless AI inference running on a global GPU infrastructure.
  • Implementation:
    • Breadth of Choice: Access to 150+ open-source models, including Large Language Models (LLMs) like Llama, Image Generation (Stable Diffusion), and Audio transcription (Whisper).
    • Active Demo: Powers the interactive AI chat partners in CF Messenger using the Llama 3.2 model.
  • Competitive Edge:
  • Reduced Latency: Unlike centralised APIs (such as OpenAI) that route data to specific regions, Workers AI runs on GPUs in over 150+ cities globally. This places intelligence directly next to the user for faster responses.
    • Cost Transparency: Cloudflare avoids the complex token-based “bill shock” often found in proprietary APIs, offering a more predictable and cost-effective scaling model.
  • The Concept: A privacy-focused, non-interactive CAPTCHA alternative.
  • Implementation: Secures authentication endpoints against automated bots without disrupting the user experience with challenges.

While the Proof of Concept (PoC) prioritises speed and real-time interaction, a production-scale deployment would integrate these additional services:

  • D1 (Relational Database): For persistent, structured storage of user profiles and long-term chat history.
  • R2 (Object Storage): For cost-effective storage of profile images and shared media with Zero Egress Fees.
  • WAF (Web Application Firewall): To implement advanced security rules and custom rate-limiting protections.
  • Cloudflare Pages: For optimised global hosting of static assets like frontend scripts and styles.
  • Cloudflare Access: To provide secure identity-based access control for administrative and backend dashboards.

[!TIP] This architecture is optimised for low-latency, real-time communication. By deploying logic and state at the Edge, we eliminate the distance-related delays typical of centralised data centres.