One Platform, Many Partners, and No Way to See Each Other’s Data
The AI tools on this site (plant knowledge assistant, robot-cell copilot, data analyst agent, planning copilot and
maintenance language model) only matter if people at the partner companies can sign in and use them. This is the
multi-tenant GenAI platform that hosts them. It gives each partner an isolated workspace with its own sign-in,
streaming chat and tools, API keys for its own systems, and a usage meter that shows exactly what each partner
consumed. The partners include competitors, so isolation between tenants is the first requirement, not a feature.
ContextUniversity of Skövde · AI-COMPETE (Vinnova) & SMART (KK-stiftelsen) · 2026 · system design
Next.js (App Router, SSR)React + TypeScriptServer-sent eventsFastAPIPostgreSQL (row-level security) + pgvectorRedisAzure API ManagementMicrosoft Entra ID (OIDC)Azure OpenAIAzure Container AppsOpenTelemetryPlaywright
ResultSystem design — product scope, tenancy model, gateway, metering and hosting. No usage figures are claimed yet.
What this page is. A system design for the platform layer of AI-COMPETE and SMART. It is not a
report of a deployment at any partner. Figures marked target are release gates. They are not measured
results.
Stakeholder engagement · product scope
A research prototype that partners can actually log into
Most programme software dies as a notebook on one researcher’s laptop.
Industry–academia programmes often end with working models that no partner employee ever used, because
running them needed the researcher. The platform closes that gap. Engineers at each partner sign in with their
own company account, use the AI tools in a browser, and connect their own systems through an API. The programme
can also see who used what, so the partners’ in-kind hours and the cloud bill can be tied to actual use.
Sign-inSingle sign-on with each partner’s own Entra ID tenant, with no new passwords.
WorkspacesOne per partner, and optionally per plant, with its own documents, data
connections and members.
Streaming chatToken-by-token answers, tool steps shown live, and sessions that persist
across devices.
API keysWorkspace-scoped keys so a partner’s MES or BI tool can call the agents
directly.
UsageTokens, tool calls and GPU seconds per workspace, user and tool, shown on a live
dashboard.
Architecture
Every request crosses the same four checkpoints
Identity, gateway, tenant-scoped data and the metering ledger.
The gateway decides who you are, the database decides what you can see, and the ledger records what you used.
Front end
Fast to first paint, and fast to first token
Next.js with server rendering for the frame and streaming for the answer.
Server-rendered shell. The App Router renders the workspace, session list and dashboard on the
server, with the user’s session already resolved, so the page is usable before any client JavaScript
runs.
SSE token streaming. Answers stream as server-sent events: tokens, tool-step events (“querying
maintenance history…”) and a final usage event. The event IDs let a dropped connection resume from
the last one received instead of starting over.
Optimistic UI. Messages, renames and workspace switches update locally at once and reconcile
with the server afterwards. That is what makes the interface feel faster than the model.
Live usage dashboard. Per-workspace charts of tokens, cost and tool calls, updated from the
same event stream the ledger writes.
Tested like a product. Playwright end-to-end tests cover sign-in, streaming, tenant switching
and key management on every pull request.
Multi-tenancy · security
Isolation enforced in three layers, and tested on every deploy
If one layer has a bug, the next one still stops the leak.
Layer
How tenancy is enforced
Identity
A multi-tenant Entra ID app. The partner’s tenant ID in the signed token maps to a platform tenant, and there is no self-registration.
Application
Every service call carries a tenant context taken from the verified identity. Queries without one fail closed.
Database
PostgreSQL row-level security on every tenant table, including the pgvector embeddings, so a missing WHERE clause returns nothing rather than someone else’s rows.
Retrieval & caches
Vector search, Redis keys and prompt caches are all namespaced by tenant, so a cached answer can never cross companies.
API keys
Shown once, then stored only as a hash. Each key has a visible prefix, workspace and scope limits, an expiry and one-click rotation, and every use is logged.
An automated isolation suite runs on every deploy. It creates two tenants, seeds each with marked data, then
tries every endpoint, search and cache path from one tenant to read the other. Any hit blocks the release.
Gateway, rate limits & metering
Know who used what, and stop anyone using too much
Model calls are metered precisely, because shared cloud credit is shared money.
Rate limiting
Azure API Management handles authentication and coarse per-key limits at the edge.
Redis token buckets in FastAPI apply tiered limits per workspace and per user, counted in model tokens
rather than requests, since one long analysis costs as much as a hundred short questions.
Limits return 429 with a Retry-After header and show in the UI as a friendly
countdown, not an error.
Token metering
Before a call, a tokenizer-based estimate is checked against the workspace’s remaining budget.
After the call, the provider’s reported usage is authoritative. It is written as an idempotent,
append-only ledger event: tenant, user, tool, model, tokens in and out, GPU seconds and cost.
An outbox pattern guarantees every completed call is metered exactly once, even if a worker crashes
mid-stream.
The ledger is billing-ready. The same events could drive Stripe usage-based billing through a webhook
if the platform is commercialised after the programme.
Context engineering across sessions
Long conversations, bounded context
A session can run for weeks. The prompt cannot grow with it.
Session storeEvery message, tool call and result is kept in PostgreSQL, so a session opens
exactly where it was left, on any device.
Rolling summaryOlder turns are compressed into a summary. Facts the user confirmed and
decisions they approved are pinned word for word.
Workspace memoryPlant names, line codes and preferred units are stored per workspace, so
every new session starts already knowing them.
Prompt cachingStable system prompts and workspace context come first, so the provider’s
prompt cache cuts cost and time to first token on repeat turns.
Hosting & release gates
Hosted where the partners’ data is allowed to be
Azure in Sweden Central, defined in Bicep and deployed by GitHub Actions.
Next.js and FastAPI run as containers on Azure Container Apps, next to managed PostgreSQL, Azure Cache for Redis
and the API gateway, all in the Sweden Central region. Partners’ data stays in the EU, and they already trust
Azure. A Vercel-style edge platform would be simpler to host, but it would put a third party between the partners
and their data. OpenTelemetry traces follow one request from the browser to the model and back, with a tenant ID
on every span.
Metric
How it is measured
Release gate (target)
Cross-tenant reads
Isolation suite on every deploy
0 (hard gate)
Metering completeness
Ledger events compared with provider usage, reconciled daily
100%
Time to first token
p95, from send to first streamed token, chat without tools
< 1.5 s
UI interaction latency
p95, from click to visual update, measured in the browser
< 100 ms
Gateway overhead
p95 added by authentication, rate limiting and metering