Skip to main content
Building a Business Chatbot to Scale: Architecture, Data Isolation, and the Case for Cloudflare
Matt PantaleoneMatt Pantaleone
AI Engineering
Dec 01, 2026
21 min

Building a Business Chatbot to Scale: Architecture, Data Isolation, and the Case for Cloudflare

How we build a practical business chatbot using Cloudflare, retrieval-augmented generation, and tenant-aware data architecture

Most business websites already contain the answers customers need.

The problem is finding them.

A visitor has to navigate pages, open FAQs, compare services, and work out which information applies to their situation. If they cannot find an answer quickly, they leave, send an email, or call someone who has to answer the same question again.

A business chatbot can make that information easier to use. But a useful chatbot needs more than a chat window connected to a language model.

It needs a reliable way to learn a business's content, retrieve the right information, explain where an answer came from, protect customer data, and operate predictably as more businesses use the service.

That's what we're building at Pantaleone.

The product is designed to let a business create an assistant from its existing website content, configure how it behaves, add it to its website, and use conversations to answer questions and identify potential customers.

This article explains the architecture behind that product, why we chose a Cloudflare-first approach, how retrieval works, how tenant data is separated, and what we consider as the platform scales.

The distinction throughout is important: a shared platform can serve many businesses without treating their data as shared.


1. What we're building — and what we're not

The objective is straightforward: give a business a useful assistant that can answer questions about that business.

A business should not need to build a knowledge base from scratch, manage an AI infrastructure stack, or understand vector databases to get started.

The intended setup is:

  1. A business submits its website.
  2. The platform discovers and processes relevant pages.
  3. The business reviews the content available to its assistant.
  4. The business configures the assistant's name, instructions, and behavior.
  5. The business tests the assistant.
  6. The business installs a small chat widget on its website.
  7. The business reviews conversations and any leads captured through the experience.

The assistant should answer from the business's approved information, provide source references where available, and avoid inventing details when the retrieved content does not support an answer.

This is a focused business tool. It is not intended to be a general-purpose agent that acts on its own, a replacement for a company's CRM, or a promise that a language model can safely answer every possible question.

The product has two primary jobs:

  • Customer support: help visitors find accurate information without searching through the entire website.
  • Lead generation: recognize when a visitor is interested in a product or service and make it easy to continue the conversation.

The interface should stay simple. The engineering underneath it cannot.


2. Why we chose a Cloudflare-first architecture

A chatbot has several infrastructure requirements:

  • An application runtime for the dashboard, APIs, and chat requests.
  • A relational database for accounts, assistants, settings, conversations, and leads.
  • Object storage for source documents and processed content.
  • A vector index for semantic retrieval.
  • An embedding model to convert content into vectors.
  • A language model to generate responses.
  • Background processing for website ingestion and indexing.
  • Rate limits, usage accounting, and operational visibility.

These services do not need to live on separate infrastructure providers.

We are building around Cloudflare because it provides application execution, data services, storage, and AI capabilities within one platform.

The architecture is based on these responsibilities:

LayerCloudflare serviceResponsibility
Application runtimeWorkersServe application routes, APIs, and chat requests
Relational dataD1Store accounts, assistants, configuration, conversations, and operational records
Object storageR2Store source files and larger content artifacts
Semantic retrievalVectorizeSearch embedded content for relevant passages
Embeddings and inferenceWorkers AIGenerate embeddings and model responses where configured
Background workQueues / WorkflowsProcess ingestion and other work outside the visitor request
Edge deliveryCloudflare networkDeliver the application and public chat experience

The exact service used for a particular model or workload can change as the product evolves. The important architectural decision is to keep each service responsible for a distinct part of the system.

We do not need a separate virtual machine, a container cluster, or a traditional always-running application server to serve a normal chat request.

Cloudflare Workers gives us an execution environment close to the visitor. D1, R2, and Vectorize provide separate storage capabilities, and background processing can handle work that should not hold open a visitor's request.

This keeps the operational model relatively small.


3. The high-level architecture

There are two main paths through the system:

  • The ingestion path: collect a business's content and make it searchable.
  • The conversation path: retrieve relevant content and use it to answer a visitor.

They share the same account and assistant configuration, but they have different performance requirements.

Ingestion can take time. A website may contain dozens or hundreds of pages. Pages need to be fetched, cleaned, divided into useful sections, embedded, and indexed.

A visitor waiting for an answer should not have to wait for any of that work.

Conversation path

Website visitor
      |
      v
Chat widget
      |
      v
Chat API / Worker
      |
      v
Resolve assistant and tenant
      |
      v
Load assistant configuration
      |
      v
Retrieve relevant knowledge
      |
      +--------------------+
      |                    |
      v                    v
    D1 data             Vectorize
      |                    |
      +---------+----------+
                |
                v
       Build grounded context
                |
                v
         Model inference
                |
                v
      Validate and format answer
                |
         +------+------+
         |             |
         v             v
   Source links    Lead capture
         |             |
         +------+------+
                |
                v
       Save conversation data
                |
                v
        Return answer to visitor

Knowledge ingestion path

Business website or uploaded source
                |
                v
          Ingestion request
                |
                v
       Queue / background workflow
                |
                v
       Fetch and extract content
                |
                v
        Normalize and clean
                |
                v
          Split into chunks
                |
                v
        Generate embeddings
                |
        +-------+--------+
        |                |
        v                v
       R2             Vectorize
  Source content   Searchable vectors
        |                |
        +-------+--------+
                |
                v
       D1 metadata and status

The diagrams show the logical flow. They are not a claim that every step runs in one Worker invocation or that every workload must use every Cloudflare service.


4. Turning a website into usable knowledge

The quality of a retrieval-based chatbot depends heavily on the quality of its source material.

Sending an entire website to a language model for every question is expensive, slow, and unreliable. It also makes it difficult to identify which information supports a particular answer.

Instead, we process the website before a visitor asks a question.

Step 1: Discover pages

The business provides a website URL.

The ingestion process discovers pages that are relevant to the business, subject to crawl limits and content rules. A sitemap is a useful starting point, but it is not the only possible source of URLs.

The crawler should avoid indexing irrelevant or duplicate content, including:

  • Login and account pages.
  • Search result pages.
  • Duplicate URL variants.
  • Tracking parameters.
  • Administrative routes.
  • Pages that are blocked from crawling.
  • Content outside the configured domain scope.

A business should be able to review what was discovered rather than assuming every URL belongs in its assistant's knowledge base.

Step 2: Extract and normalize content

HTML is not useful model context in its raw form.

The extraction process removes navigation, scripts, styles, repeated layout elements, and other page noise. It retains the content that carries meaning: headings, paragraphs, lists, tables, and relevant page metadata.

Normalization also matters.

The same page may be reachable through multiple URL variants. Text may contain repeated whitespace, boilerplate, or navigation fragments. These should be handled before indexing.

Each source should retain enough metadata to trace a retrieved passage back to its origin.

At a minimum, that means preserving the source URL, page title, and a stable identifier for the indexed content.

Step 3: Split content into chunks

A complete website page is often too large to use as one retrieval unit.

We split extracted content into smaller chunks. Each chunk should represent a coherent piece of information rather than an arbitrary number of characters.

For example, a page about a service might contain separate sections for:

  • What the service includes.
  • Who the service is for.
  • Pricing.
  • Delivery timelines.
  • Frequently asked questions.

Keeping those sections distinct makes it easier to retrieve the relevant answer without introducing unrelated page content.

Chunk size and overlap are engineering parameters, not universal constants. They should be evaluated against the actual content and retrieval results.

Too many small chunks can lose context. Chunks that are too large can dilute relevance and consume more model context.

Step 4: Generate embeddings

An embedding model converts each chunk into a numerical vector.

Chunks with related meaning are represented by vectors that are closer together in the embedding space. This allows the system to retrieve content based on meaning, not only exact keyword matches.

For example, a visitor might ask:

How long does delivery take?

The source page might use the heading “Estimated fulfillment times.”

Semantic retrieval can connect those concepts even though the wording is different.

The embedding model used for indexing must be compatible with the embedding model used for incoming questions. If the model or vector dimensions change, the index may need to be rebuilt.

Step 5: Store content and metadata

The system needs to retain both the searchable representation and the source material needed to construct an answer.

A useful separation is:

  • D1: account ownership, assistant configuration, source records, ingestion status, and references to indexed content.
  • R2: larger source or processed-content objects where object storage is appropriate.
  • Vectorize: embeddings and metadata used for semantic retrieval.

A vector record is not a replacement for the original source. It helps find relevant content; the application still needs to resolve the retrieved result to the source text and URL.

This separation makes it possible to update, reprocess, or delete content without treating the vector index as the only record of what was ingested.


5. How a visitor gets an answer: retrieval-augmented generation

The chatbot uses a pattern commonly called retrieval-augmented generation, or RAG.

The model does not need to memorize every business website. Instead, the application retrieves relevant information at question time and supplies that information as context for the response.

The flow is:

  1. Receive the visitor's message.
  2. Resolve the assistant being addressed.
  3. Load the assistant's configuration and permitted context.
  4. Generate an embedding for the question.
  5. Search the relevant knowledge index.
  6. Apply tenant and assistant scope to the retrieval.
  7. Select the most relevant passages.
  8. Build a prompt containing the question and retrieved context.
  9. Generate the response.
  10. Return the answer with source references where available.
  11. Save the conversation according to the product's retention and data-handling rules.

The model's job is to explain the retrieved information in a useful way. The retrieval layer's job is to find the information that is relevant.

Those are separate responsibilities.

Why source references matter

A chatbot answer should not be a black box.

If the assistant says a business offers a particular service, the visitor should be able to see the page that supports that answer.

Source references also make it easier for a business owner to review whether the assistant is using the right content.

A citation does not guarantee that an answer is correct. It does provide a way to inspect the evidence behind it.

What happens when the answer is not in the source material?

The assistant should not fill gaps with confident guesses.

If retrieval does not return sufficiently relevant material, the response should make that limitation clear. The assistant can ask the visitor to contact the business or use a configured lead-capture path.

This is an important product decision.

A chatbot that always produces an answer is not necessarily a useful chatbot. For a business, an unsupported answer about pricing, availability, policies, or services can create more work than it saves.

The system should favor a clear limitation over invented detail.


6. Data isolation: one platform, separate businesses

Multi-tenancy is one of the most important parts of the architecture.

The platform is shared. Each business's data must remain scoped to that business.

A business should never be able to retrieve another business's source content, conversations, leads, settings, or usage records.

This cannot be left to the chat prompt or to the model. It has to be enforced by the application and data-access layer.

The ownership model

A simplified relationship looks like this:

Platform
  |
  +-- Account A
  |     |
  |     +-- Assistant A1
  |     |     +-- Sources
  |     |     +-- Conversations
  |     |     +-- Leads
  |     |
  |     +-- Assistant A2
  |           +-- Sources
  |           +-- Conversations
  |           +-- Leads
  |
  +-- Account B
        |
        +-- Assistant B1
              +-- Sources
              +-- Conversations
              +-- Leads

The account is the business-level ownership boundary. Assistants and their related records belong to an account.

The database schema should make those relationships explicit.

For example:

accounts
  id

assistants
  id
  account_id

sources
  id
  account_id
  assistant_id

conversations
  id
  account_id
  assistant_id

leads
  id
  account_id
  assistant_id

The actual schema can evolve, but the ownership relationship should remain clear and enforceable.

D1 queries must be tenant-scoped

A query that loads a conversation by its ID alone is not sufficient for an authenticated business dashboard.

The query also needs to verify that the record belongs to the authenticated account.

Conceptually, avoid this:

SELECT *
FROM conversations
WHERE id = ?;

Use an account-scoped query:

SELECT *
FROM conversations
WHERE id = ?
  AND account_id = ?;

The account ID must come from trusted server-side authentication and authorization context. It must not be accepted as an authoritative value simply because the browser sent it.

The same rule applies to assistants, sources, leads, usage records, and every other tenant-owned object.

Vector search must be tenant-scoped too

Filtering relational database queries is only part of the problem.

The vector index also needs a tenant boundary.

A vector record can carry metadata such as:

{
  "account_id": "account_123",
  "assistant_id": "assistant_456",
  "source_id": "source_789"
}

At retrieval time, the application must derive the permitted account and assistant scope from the resolved assistant record, then apply that scope to vector search.

Vectorize supports metadata filtering and namespaces. These can be used as part of a tenant-aware retrieval design.

The critical point is that a namespace or metadata filter is not useful if the application lets an untrusted client choose another tenant's value.

The server must decide which namespace and filters apply.

R2 objects need ownership checks

Object storage also needs a clear ownership convention.

A key structure might look like:

accounts/{account_id}/assistants/{assistant_id}/sources/{source_id}/...

The object key helps organize data. It is not an authorization mechanism by itself.

Before returning an object or creating a signed URL, the application must verify that the requesting account owns the associated source or assistant.

Conversations and leads are private business data

Conversation records can contain personal information submitted by visitors. Leads can contain names, email addresses, phone numbers, and messages.

These records need the same tenant checks as the knowledge base.

They also need explicit retention, deletion, and access policies. Those policies should be documented and implemented rather than inferred from the fact that the data is stored on Cloudflare.

Shared infrastructure does not mean shared access

The platform can share application code and underlying services while keeping each business's records logically separate.

This is a common multi-tenant architecture.

For customers with requirements that go beyond logical separation, the data layer can evolve to support stronger isolation, such as dedicated databases or other tenant-specific resources. That is an architectural option, not a claim that every customer currently receives a separate database.


7. How the platform scales

A platform does not scale simply because it runs on an edge network.

It scales when the application separates workloads, limits resource consumption, and avoids making every request do unnecessary work.

There are several design choices that help.

Stateless request handling

Workers execute application requests without requiring a permanently running application server for each customer.

The application should keep durable state in the appropriate storage service rather than relying on in-memory process state.

That allows the runtime to handle requests across many instances without needing to maintain a long-lived server process for each business.

Keep ingestion off the chat request path

Website ingestion is variable work.

Fetching pages, parsing HTML, generating embeddings, and updating an index can take significantly longer than answering a visitor's question.

That work belongs in a background pipeline.

The visitor-facing request should retrieve from an existing index. If the business is still processing content, the application can show the indexing status rather than making the visitor wait for a crawl.

Queues and Workflows are useful tools for this separation. They also provide a place to manage retries and multi-step processing, subject to the behavior and limits of the selected service.

Separate the storage responsibilities

D1, R2, and Vectorize solve different problems.

Using each for its intended purpose avoids forcing one service to do everything.

  • D1 stores structured application records.
  • R2 stores larger objects.
  • Vectorize supports semantic retrieval.

The application coordinates these services and maintains the relationships between them.

Plan for database boundaries

A shared D1 database can support multiple tenants when every access path enforces tenant scope and the workload fits the database's capacity and limits.

As usage grows, database partitioning or dedicated per-tenant databases may become appropriate.

That decision should be based on measured workload, operational requirements, and isolation needs—not on an assumption that every customer needs a separate database from day one.

Control usage at the application layer

The platform needs to account for more than the number of chat messages.

Relevant usage dimensions include:

  • Model input and output tokens.
  • Embedding generation.
  • Vector search operations.
  • Website pages processed.
  • Re-indexing and retries.
  • Stored content and conversation history.
  • Rate limits and concurrent requests.

Usage enforcement should happen on the server. The client interface can display limits, but it cannot be trusted to enforce them.

This is also the basis for sensible product tiers. Limits should reflect actual infrastructure consumption and the value delivered to each business.


8. Reliability and operational controls

A chatbot is part of a business's customer experience. It needs to fail in a controlled way.

A few operational practices are especially important.

Idempotent ingestion

A website crawl may be retried because a request times out or a background job fails.

The ingestion process should be designed so that retrying a step does not create duplicate source records or uncontrolled duplicate vectors.

Stable source identifiers, versioning, and explicit indexing status help make that possible.

Timeouts and bounded work

A chat request should have limits on retrieval time, model execution, and total response duration.

An ingestion job should have limits on pages, content size, retries, and processing time.

Without bounds, a single unusually large website or expensive request can consume disproportionate resources.

Rate limiting

Public chat endpoints can be abused.

Rate limits should consider the assistant, visitor/session, and broader account usage. Additional controls may be appropriate for suspicious traffic or unusually high request volume.

Observability

The system needs enough operational data to answer questions such as:

  • Which ingestion step failed?
  • How many pages were processed?
  • How long did retrieval take?
  • How many passages were returned?
  • Did the model produce an answer?
  • Was a source reference included?
  • How much usage did the request consume?
  • Did a tenant-specific limit apply?

Logs and metrics should avoid exposing unnecessary visitor content or credentials. Access to operational data also needs to be controlled.

Deletion and re-indexing

A business needs a way to remove outdated or unwanted source content.

That means deleting or invalidating the corresponding records in the relational database, object storage, and vector index.

The same applies when a business disconnects a source or closes its account.

Deletion should be a defined workflow with verification, not an assumption that removing one database row removes all copies of the content.


9. Why not deploy a separate chatbot application for every business?

A separate application for every customer sounds simple at first.

It also creates a large operational burden.

Each deployment needs its own application configuration, updates, monitoring, and release process. A change to the chat interface or retrieval logic becomes a fleet-management problem.

A multi-tenant platform avoids that duplication.

The application code is shared. Business-specific configuration, knowledge, conversations, and leads are scoped to the appropriate account and assistant.

That gives us one product to maintain while supporting many business deployments.

There are legitimate reasons to offer dedicated infrastructure for a larger customer. Some businesses have specific contractual, regulatory, or operational requirements.

That should be an explicit deployment and pricing decision, not the default architecture for every small business.


10. The business experience should stay simple

The infrastructure is complex. The setup should not be.

A business owner should not need to know what an embedding is, how vector search works, or which database stores a conversation.

The self-service experience is designed around a short sequence:

  1. Create an account. Establish the business account and owner.
  2. Add a website. Provide the domain or starting URL for the knowledge source.
  3. Review content. See which pages were discovered and indexed.
  4. Configure the assistant. Set its name, instructions, and behavior.
  5. Test responses. Ask real questions and inspect the supporting sources.
  6. Install the widget. Add the embed snippet to the business website.
  7. Manage conversations. Review visitor questions and captured leads.

The business should remain in control of what information its assistant uses.

A review and test step is important. A website crawl can find content that is outdated, duplicated, or not intended for customer-facing answers. The business needs a way to catch that before publishing.

The goal is not to expose infrastructure settings. It is to make the product understandable and manageable.


11. Why this architecture is a good fit for small and growing businesses

Most small businesses do not need a custom AI platform.

They need a reliable way to answer common questions, help visitors understand their services, and capture interest when someone is ready to take the next step.

A focused assistant can help with questions about:

  • Services and product details.
  • Pricing information published on the website.
  • Business hours and location.
  • Policies and processes.
  • Appointment or consultation options.
  • Delivery and fulfillment information.
  • Common support questions.

The business retains its existing website and customer workflows. The chatbot makes the information on that website easier to access.

The Cloudflare-first architecture gives us a compact foundation for delivering that capability without operating a separate server stack for every customer.

It also gives us room to evolve the platform: more ingestion sources, additional configuration, stronger tenant isolation options, and more detailed usage controls can be added as actual customer requirements emerge.


12. The engineering principle: simple product, deliberate infrastructure

A chatbot demo is easy to build.

A business product is different.

It needs to retrieve the right information, identify which business owns that information, prevent cross-tenant access, handle background work, manage usage, and provide a predictable experience when the answer is not available.

Those requirements shape the architecture.

We use a shared application platform because it is easier to maintain and improve. We separate tenant data because customer information must remain private. We separate ingestion from live conversations because they have different performance requirements. We use retrieval because answers should be grounded in a business's actual content.

The model is one component in that system. It is not the system.

That's the approach behind the Pantaleone business chatbot: a focused customer-facing tool, backed by infrastructure designed to support multiple businesses without making the product complicated to use.

Explore the Pantaleone custom business chatbot or visit Pantaleone to learn more.

On this page

Work together?

Bring one workflow to a 30-minute call.

Book a call

Last updated: December 1, 2026