Reference architecture: responsibilities before tools

Step 3 of 14. Split Store Assist into six layers, decide which layer owns which job and which data store is the source of truth, and give every kind of request its own path. Name the tools last.

Reference architecture in 60 seconds

  • What: six layers (client, entry, application, AI processing, data, operations), each with a clear job.
  • Order of work: decide responsibilities and data flow first. Pick products last.
  • Orchestrator: a thin, testable router that sends each request type down its own path, so cheap questions never pay for expensive machinery.
  • Truth: every kind of data has one source of truth. The vector index finds passages. It does not know a colleague's current ticket.
  • Rule of thumb: nothing privileged lives in the client, and every service can be restarted without losing a conversation.

The problem it solves

Teams often start a design by choosing a search product, an orchestration library or a model supplier. Those choices feel productive, but they hide the real questions. Who decides which path a request takes? Where does a colleague's stock query get its answer? What happens to a conversation if one service restarts at 08:05 on a Monday?

The capacity step gave Store Assist a shape: 36,000 requests a day, a peak near 10 requests per second and around 25 requests in flight. This step decides what those requests flow through. Start from jobs and data, and the tool choices in later steps become small, reversible decisions rather than foundations you cannot change.

The six layers

Each layer below answers one question: what is this layer allowed to know, decide and do? If a job could sit in two layers, pick the one with the stronger controls.

Six layers, each with one job, with operations watching all of them.

Client layer

The client is whatever colleagues use to ask a question and read the answer. For Store Assist that is the store app and the handheld scanner screen. It could equally be a panel inside the company chat tool.

  • Never in the client: provider keys, signing secrets, prompt templates, routing rules, price or refund limits, and any check that decides what a colleague may see.
  • Fine in the client: display, input capture, local drafts, streaming rendering and a cancel button.
  • Assume tampering: a handheld can be rooted and a request can be replayed. The server must treat every client field as a claim, not a fact.

Entry layer

The entry layer is the controlled doorway. Everything that arrives passes through it before reaching business logic. It covers these jobs:

  • An API gateway that terminates connections and routes traffic.
  • Hand-off to company sign-on for identity checks.
  • Rate limits and quotas.
  • Request validation, including size caps.
  • Filtering of obviously bad traffic.
  • Load balancing across healthy application instances.

Its purpose is to make sure all traffic arrives by a path you control. The next step goes deeper into what it enforces. For the pattern itself, see API gateway and load balancing.

Application layer

This is where the backend logic lives. It holds the conversation, works out what sort of request has arrived, checks the caller's permissions and chooses a processing path. The component that does the choosing is the orchestrator. It may route a request to a manuals pipeline, to an approved business service, to a plain deterministic handler or to a human workflow at the store support desk.

AI processing layer

Everything that touches a model sits here, and not every request needs all of it. The candidates are:

  • An intent classifier, to label the request type.
  • A semantic cache, for repeated safe questions.
  • A retrieval pipeline over approved store manuals.
  • A model router, to pick a model for the job.
  • An AI gateway in front of providers.
  • Input and output safety checks.

Three contrasting requests show why the layer is optional by design. A greeting such as "thanks" gets a canned reply with no model call. A scanner sync question needs retrieval. A request to reset a till PIN must go to an authorised identity workflow, and the model should never write instructions that pretend the reset is done.

Data layer

The data layer holds what the application needs to know. Its parts have different jobs, and mixing them up is a classic design fault.

  • Approved store manuals and procedures in a document repository.
  • A vector index for finding relevant passages in those documents.
  • Incident tickets held by the ticketing service.
  • Stock and order data held by the inventory and order services.
  • Operational databases with authorised application data, such as rotas.
  • A cache for reusable answers.

A vector index is good at finding passages. It is not the place to ask whether incident INC-5521 is open, because its copy of the world is always a little old. For each kind of data, name one system as the source of truth and make everything else a derived copy that can be rebuilt.

Operations layer

Operations covers the work that keeps the system healthy after launch:

  • Logs, metrics and traces.
  • Quality evaluations run on samples of real traffic.
  • Dashboards and paging rules.
  • Automated releases.
  • Backups and restore drills.

Without it you cannot tell whether answers are getting slower, dearer or less accurate until colleagues complain. Steps 12 and 13 cover it in detail.

Following one request down the stack

Take a colleague who asks, "Why won't my handheld scanner sync since this morning's update?" The steps below are a simplified happy path.

One troubleshooting question, nine hand-offs, and a metrics record at the end.
  1. The colleague sends the question from the app.
  2. The gateway applies size, rate and sign-in checks.
  3. The backend establishes who the colleague is, which store they work in and what they may do.
  4. The orchestrator labels the request as troubleshooting.
  5. The retrieval pipeline searches approved manuals, filtered to what this colleague may read.
  6. A suitable model drafts an answer from the retrieved passages and, where useful, a live device-management lookup.
  7. Output checks run against the safety and policy rules.
  8. The answer returns to the colleague, streaming where possible.
  9. The system records timings, token counts and a quality sample.

A question about incident INC-5521 takes another path. It needs current ticket data, so the orchestrator calls the ticketing service directly and lets the model phrase what comes back. That difference is why an orchestrator exists. It routes by request type, rather than pushing all messages down one costly pipeline.

Request-type catalogue

A catalogue is a short table that lists every type of request the system supports and the path each one takes. It turns the orchestrator from a vague idea into something you can test, and it stops teams from adding a new request type without deciding its controls first.

Request typeExamplePathSource of truth
Small talkThanks, that workedDeterministic handler, no modelNone
Procedure questionWhy won't my handheld scanner sync?Cache check, retrieval, model, output checksApproved manuals
Live data lookupUnits of SKU 448812 in the stockroom, status of INC-5521Direct call to the inventory or ticketing service, model phrases the resultInventory and ticketing services
Personal dataHow many holiday hours do I have left?Authorised call to the rota service, never cached for othersRota and HR services
Sensitive account actionReset my till PINIdentity verification workflow, not generated textIdentity service
Action needing approvalRefund over £150, price overrideDraft by the model, approval by a store manager, execution by the serviceOrder and pricing services
Out of scope or unsafeA request to reveal the regional store closure planPolite refusal, logged, optional hand-offDocument permissions

Keeping the pieces simple to run

  • Stateless services: application instances hold nothing a restart can lose. Conversation state lives in a shared store, so any instance can serve the next turn.
  • Thin orchestrator: it classifies, checks permissions and picks a path. Business rules stay in the services that own them. A thin router is easy to unit test with a table of example requests.
  • Modular monolith first: one deployable with clean module boundaries is easier to run than twelve services. Split a module out when load, ownership or release speed demands it. Compare the trade-offs in architectural patterns.
  • One owner per data type: if two systems both claim to know a colleague's rota, they will disagree during an incident.

Store Assist, worked through

Apply the layers to the numbers. At peak, 10 requests per second reach the entry layer. Roughly 25 are in flight at once for a plain question, and about 70 for a three-tool agent flow of 7 seconds. Those figures size the connection pools and worker counts in the application layer. They are not the same as the 1.0 request per second average, so do not size to the average.

Now estimate how traffic divides by path. Suppose a first guess is 55 percent procedure questions, 25 percent live lookups, 8 percent personal data, 7 percent small talk, 3 percent approvals and 2 percent sensitive actions. Of 36,000 daily requests, that is about 19,800 procedure questions, 9,000 live lookups, 2,880 personal queries, 2,520 small talk, 1,080 approvals and 720 sensitive actions. Small talk needs no model, so about 7 percent of traffic costs almost nothing. These percentages are assumptions to replace with real logs after the pilot.

A cost target helps too. The goal is under £0.03 per resolved question. A path that skips the model, such as small talk, costs far less than that. A path that does retrieval, two tool calls and a long answer will cost more. The mix matters more than any single path, so the orchestrator should log which path each request took.

A thin orchestrator that routes by request type (illustrative) (python)
from dataclasses import dataclass

MAX_TOOL_CALLS = 3        # hard cap per request
MAX_INPUT_TOKENS = 1_000  # prompt budget for one request
REQUEST_DEADLINE_S = 8.0  # full-answer budget (p95 target)

@dataclass
class Caller:
    colleague_id: str
    store_id: str
    role: str

def orchestrate(text: str, caller: Caller, services) -> dict:
    # Classification only labels the request. It grants nothing.
    kind = services.classifier.label(text)   # placeholder component

    if kind == "small_talk":
        return {"path": "canned", "answer": services.canned.reply(text)}

    if kind == "procedure":
        passages = services.retrieval.search(
            text, caller=caller, top_k=5)        # filtered by permissions
        answer = services.model.answer(text, passages,
                                       max_tokens=250,
                                       deadline_s=REQUEST_DEADLINE_S)
        return {"path": "rag", "answer": answer}

    if kind == "live_lookup":
        # Authoritative service answers. The model only phrases the result.
        facts = services.live.lookup(text, caller=caller)
        return {"path": "live", "answer": services.model.phrase(facts)}

    if kind in ("sensitive_action", "needs_approval"):
        # Never answered by generated text. Start a tracked workflow.
        ticket = services.workflow.start(kind, text, caller=caller)
        return {"path": "workflow", "workflow_id": ticket}

    # Unknown types fail closed, not open.
    return {"path": "refuse", "answer": "I cannot help with that here."}

Every service on services is a placeholder. Two details matter. The classifier only labels a request and has no power to grant anything. Unknown request types are refused by default.

Design decisions

  • Layer ownership: name one team per layer. Shared ownership usually means nobody is paged.
  • Source-of-truth register: a one-page table of each data type, its owning service, its allowed derived copies and how fast those copies must catch up.
  • Orchestration style: begin with deterministic routing on request type. Add model-assisted routing only when the catalogue stops being enough. See router.
  • Where state lives: conversation history and workflow state in a shared store with a time to live. Never in instance memory.
  • Deployment shape: modular monolith for the application layer at launch, with the AI gateway and indexing workers as separate deployables because their scaling and failure behaviour differ.
  • Fail-closed defaults: an unrecognised request type, a missing permission or an unavailable policy service means refuse and log.

Measuring it

  • Routing accuracy: the share of a labelled request set that lands on the correct path. Track the confusion between live lookups and procedure questions closely.
  • Path mix: requests per path per day, compared with the catalogue assumptions. A sudden shift often signals a release problem or a new colleague habit.
  • Wrong-path cost: how often a request that should have skipped the model still paid for one.
  • Cost and latency per path: p50 and p95 for each path, not one blended figure.
  • Fallback rate: how often the unknown-type refusal fires, and which requests triggered it.

When to use it, and how much of it

SituationArchitecture to useWhy
One read-only FAQ for a single teamClient, entry, one backend, retrieval, basic logsFew request types and no actions. A full orchestrator is more than you need.
Live lookups and personal dataAdd an orchestrator, a source-of-truth register and per-user permission checksDifferent request types need different paths and different controls.
Actions that change recordsAdd workflow state outside the model and an approvals pathActions need tracking, limits and a human where the risk is high.
Several teams building AI featuresShared entry layer, AI gateway and evaluation platformCommon controls avoid every team rebuilding them differently.
Strict regulatory or audit demandsFull six layers plus detailed audit trailsYou need to prove who asked, what was retrieved and what was done.

Trade-offs

DimensionEffectWhat to do about it
Delivery speedDrawing layers and a catalogue takes a few days before any feature ships.Keep the first catalogue to four or five request types and grow it with evidence.
LatencyEach extra hop adds time. Layers that do nothing for a request type are pure cost.Let simple requests skip optional layers, and set a time budget for each hop.
CostRouting saves model spend on simple requests, but adds components to run and pay for.Track cost per path and drop components that do not earn their keep.
FlexibilityClear boundaries make tools replaceable, yet too many boundaries slow small changes.Start as a modular monolith and split only on measured need.

What this means for your role

Common mistakes

Step checklist

  • A one-page layer map names an owner for each of the six layers.
  • Nothing privileged exists in the client: no keys, no limits, no routing logic.
  • A request-type catalogue lists each type, its path and its source of truth.
  • Unknown request types refuse by default and are logged.
  • Every data type has one named source of truth and a list of derived copies.
  • Application instances are stateless and survive a restart mid-conversation.
  • The orchestrator is covered by tests built from example requests for every catalogue row.
  • Each path reports its own cost and latency.

Further reading

You now have the layers, the paths and the data ownership for Store Assist. The next question is who is allowed through the door, and how much each caller may use. Next: Step 4: Identity, access and limits.

Search topics

↑↓ to move · Enter to open · Esc to close