Design a secure API for an AI assistant
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Microsoft's system design round, last asked Apr 2026. It tests security, authentication and authorization.
Design the API for an enterprise AI assistant that many separate organizations (tenants) use. Signed-in users send prompts and get responses; the assistant can call organization-specific tools and read from tenant-private knowledge sources. The interviewer cares mainly about security: authentication, authorization, the token lifecycle, abuse prevention, and what changes at very large scale across regions.
Requirements
- Functional: chat endpoints for prompts and responses (streamed); tool invocation; retrieval from tenant knowledge; admin and audit endpoints.
- Non-functional: strict tenant isolation; interactive latency, so per-request checks must be cheap; tenants bring their own identity providers (OIDC or SAML); tools can take real actions; tamper-resistant audit logs and data controls (retention, training opt-out, residency); secure by default and fail closed.
Clarifying questions
- Which identity providers must we federate with, and is configuration per tenant?
- Are tools first-party only, or can tenants register their own?
- What are the residency and retention rules for prompts and outputs?
- What scale and latency targets apply?
- Do some tenants need isolated deployments?
- Which privileged roles exist (tenant admin, operator, auditor)?
What a strong answer covers
- A threat model first: assets (tenant data, tools, signing keys), adversaries (stolen token, malicious tenant, a model steered by injected text), and trust boundaries.
- Components: gateway and WAF, authentication, a policy engine, an orchestrator, tenant-scoped retrieval, a sandboxed tool layer, a model gateway, audit and key management.
- Authentication: OIDC SSO with short-lived user tokens; workload identity or mTLS between services, not static keys.
- Authorization: roles plus attributes and scopes; tenant identity taken from trusted token claims and re-checked at every hop (retrieval, tools, storage); document-level access in retrieval; tool permissions checked per call.
- Token lifecycle: claims, asymmetric signing in a KMS or HSM,
kidand a JWKS endpoint, local validation of signature, issuer, audience, expiry and tenant, key rotation with overlap, and revocation through short TTLs, refresh-token revocation and ajtidenylist. - Misuse controls in layers: rate limits, quotas and cost caps; replay and theft defences (proof-of-possession tokens, nonces); tool allowlists, sandboxing and SSRF protection; treating retrieved text as untrusted; redacting logs.
- Scale and reliability: cached validation and policy decisions with correct invalidation, distributed tenant-aware rate limiting, key replication across regions, security monitoring, and fail-closed behaviour.
Follow-ups
- A user's token is stolen and replayed from a new IP within its lifetime. Which controls detect it, contain it and revoke it, and how long is the exposure?
- The policy engine slows down at peak. How do you stay available without serving a stale "allow" after a permission was revoked?
- A retrieved document tells the model to call a deployment tool and send another tenant's data out. Which boundaries stop it?
- A customer demands no shared infrastructure and in-region data only. How do you support that, and at what cost?
Where it's asked
- Microsoft · System design · Last asked Apr 202660 min · Design discussion
What it tests
security · authentication · authorization · api design
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
