Problem Statement
Design a platform that serves hundreds of enterprise tenants, each of whom can optionally fine-tune (or adapter-tune) a shared base LLM on their own proprietary data. The platform must guarantee strict tenant data isolation (a tenant’s fine-tuning data and adapter weights must never leak to another tenant, even accidentally through shared GPU memory or caches), run on shared infrastructure for cost efficiency (you cannot afford one dedicated GPU cluster per tenant), and serve inference requests such that no single tenant’s traffic spike starves other tenants of latency/throughput (noisy-neighbor problem).
Requirements Clarification
Functional
- Tenants upload training data (documents, Q&A pairs, chat transcripts) via API/UI; platform runs a fine-tuning job producing a tenant-specific artifact.
- Support two tuning strategies: parameter-efficient (LoRA/QLoRA adapters, tens of MB) as the default, and full fine-tune only for a small number of premium tenants (opt-in, higher cost passed through).
- Inference requests reference a tenant ID; platform must route to the correct base model + adapter combination.
- Tenants can have multiple adapter versions (staging/prod), roll back, and A/B test.
Non-functional — clarify with interviewer, then assume
- Assume 400 tenants, 90% use LoRA adapters (rank 16–64, ~20–200MB each), 10% (40 tenants) are large enough to justify full fine-tunes or higher-rank adapters.
- Assume aggregate platform inference load: 5,000 QPS peak across all tenants, highly skewed (Zipfian) — top 20 tenants generate 70% of traffic, long tail of 300+ tenants generate <1 QPS each.
- p99 latency target: 800ms time-to-first-token, 40ms/token streaming, for a 7B–13B class base model.
- Isolation requirement: SOC2/ISO27001-style tenant data segregation; a tenant’s fine-tuning corpus must be encrypted at rest with tenant-specific keys and never co-mingled in shared training runs.
- Cost target: infrastructure cost per tenant should trend toward shared-infra economics, not 1:1 dedicated GPU cost (a dedicated A100 per idle tenant would be ~$2–3/hr × 400 tenants = untenable).
- Base model set: 2–3 base models (e.g., a general 8B and a general 70B) that all tenant adapters are trained against — tenants pick a base tier.
Assumptions stated explicitly to interviewer
- Adapters are LoRA-style: base model weights frozen and shared across tenants in GPU memory; only small adapter deltas differ per tenant. This is the entire crux of the design — without this, multi-tenant serving is not shared-infra feasible at all.
- Training jobs are asynchronous/batch (not part of the low-latency serving path).
Architecture Diagram
┌───────────────────────────┐
│ Tenant Control Plane │
│ (Admin UI / API, Auth) │
└──────────────┬─────────────┘
│
┌────────────────────────────┼─────────────────────────────┐
│ │ │
┌───────▼────────┐ ┌─────────▼─────────┐ ┌─────────▼─────────┐
│ Data Ingestion │ │ Fine-Tuning │ │ Adapter Registry │
│ Service │ │ Orchestrator │ │ (metadata + S3 │
│ (per-tenant │ │ (K8s Jobs / Ray) │ │ pointer to weights)│
│ encrypted │ │ - LoRA training │ │ version, base_model,│
│ bucket, tenant │──────────▶ - eval harness │────────▶ status, checksum, │
│ KMS key) │ │ - safety/PII scan │ │ rollback pointer │
└──────────────────┘ └──────────────────────┘ └─────────┬───────────┘
│
adapter pull (cached)
│
┌────────────────────────────────────────────────────────────────────────────────────▼──────────────────────────┐
│ Inference Serving Layer │
│ │
│ ┌──────────────┐ ┌──────────────────────┐ ┌────────────────────────────────────────────────────┐ │
│ │ API Gateway │─────▶│ Tenant Router / QoS │─────▶│ GPU Serving Pool (per base-model tier) │ │
│ │ (authN, │ │ - tenant_id -> shard │ │ ┌──────────────────────────────────────────────┐ │ │
│ │ quota check)│ │ - fairness scheduler │ │ │ Multi-LoRA Serving Node (e.g. vLLM + │ │ │
│ └──────────────┘ │ - priority tiers │ │ │ S-LoRA / Punica batched adapter kernels) │ │ │
│ └──────────────────────┘ │ │ - Base weights resident once in GPU HBM │ │ │
│ │ │ - LRU cache of hot adapters (e.g. 64 slots) │ │ │
│ │ │ - Continuous batching across tenants │ │ │
│ │ │ - Per-request adapter injected at attention │ │ │
│ │ │ layer via batched matmul │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ Cold adapters fetched from Adapter Registry │ │
│ │ (S3/blob) on cache miss, ~50-150ms load │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
│ │
┌───────▼────────┐ ┌────────▼────────┐
│ Usage Metering │ │ Observability │
│ (per-tenant │ │ (per-tenant │
│ token counts, │ │ latency/error │
│ billing) │ │ dashboards, │
└─────────────────┘ │ drift/quality │
│ monitors) │
└────────────────────┘
Isolation boundary: tenant data at rest = per-tenant KMS-encrypted bucket.
tenant data in training = single-tenant training job, no cross-tenant batches.
tenant data at inference = adapter weights only (no raw data), adapter never
mounted into another tenant's request context.
Key Design Decisions
-
LoRA/adapter-based multi-tenancy vs. full fine-tune per tenant.
- Chosen: LoRA (or similar PEFT — QLoRA, IA3) as default. Base model weights (the expensive multi-GB part) are loaded once per GPU node and shared read-only across all tenants; only a small adapter (tens of MB, <1% of base params) differs per tenant.
- Alternative: full fine-tune per tenant, each tenant gets a full copy of model weights.
- Trade-off: full fine-tune gives marginally better task adaptation for tenants with very large, unusual corpora, but multiplies storage (7B model ≈ 14GB in fp16 × 400 tenants = 5.6TB vs. LoRA at 100MB × 400 = 40GB) and destroys the ability to batch tenants together on shared GPUs — you’d need 400 loaded models, which does not fit in any reasonable GPU fleet. Decision: LoRA for the 90% tier; reserve full fine-tune for the <10% premium tier who get semi-dedicated capacity and pay a premium reflecting real dedicated cost.
-
Multi-LoRA batched serving (S-LoRA / Punica-style kernels) vs. one model server process per tenant.
- Chosen: a serving layer capable of batching requests from different tenants into the same forward pass, applying each request’s adapter via a batched low-rank matmul at the relevant layers (this is what frameworks like S-LoRA, LoRAX, vLLM’s multi-LoRA support, or Punica kernels provide).
- Alternative: spin up one model process (with adapter merged in) per tenant, scale replicas per tenant.
- Trade-off: per-tenant processes are simpler operationally and give hard isolation, but GPU utilization collapses for the long tail (300+ tenants at <1 QPS would each need a warm GPU replica, mostly idle) — cost-prohibitive. Batched multi-LoRA serving lets one GPU node serve dozens of tenants concurrently at high utilization, at the cost of more complex serving infrastructure and a shared-fate blast radius (a serving node bug affects many tenants at once).
-
Adapter caching strategy — hot/warm/cold tiers.
- Chosen: LRU in-GPU-memory cache of the top N hot adapters (sized to top ~20 tenants who generate 70% of traffic) kept always resident; warm tier in host RAM for adapters used in the last hour; cold tier fetched from blob storage on demand (adapter load ~50–150ms, acceptable as a one-time miss penalty, not on every request).
- Alternative: load all 400 adapters into every GPU node’s memory permanently.
- Trade-off: with adapter sizes of 20–200MB, 400 adapters could be ~40–80GB — feasible on host RAM but not always on GPU HBM alongside a large base model; permanently resident everywhere wastes memory and PCIe bandwidth for tenants who rarely call. LRU caching trades a small tail-latency cost (cache miss) for much better memory efficiency, matching the Zipfian traffic distribution.
-
Fairness / QoS scheduling to prevent noisy-neighbor starvation.
- Chosen: weighted fair queuing at the tenant router, with per-tenant token-bucket rate limits (tied to their subscription tier) and a priority-tier system (e.g., 3 tiers: premium dedicated-capacity, standard shared-pool with guaranteed minimum QPS, best-effort). Continuous batching scheduler is adapter-aware: it caps how many consecutive slots in a batch one tenant can occupy so a burst from tenant A cannot monopolize a batch window that also serves tenant B.
- Alternative: simple FIFO global queue.
- Trade-off: FIFO is simpler but a single tenant’s traffic spike (e.g., a batch job hitting the API at 500 QPS) would inflate p99 latency for everyone sharing that GPU pool. Weighted fair queuing adds scheduling complexity and requires careful tuning of quotas per tier, but is the only way to give a contractual latency SLA to standard/premium tenants on shared infrastructure.
-
Tenant data isolation model — encryption boundary and training job isolation.
- Chosen: each tenant’s raw training data lives in a per-tenant bucket/prefix encrypted with a tenant-specific KMS key; the fine-tuning orchestrator runs each tenant’s training job in an isolated compute context (dedicated container/pod with no shared filesystem mount to other tenants) that decrypts data only for the duration of that job; adapters produced are tagged with tenant_id and a lineage hash; at serving time, only adapter weights (never raw training text) cross into the multi-tenant serving fleet, and the router cryptographically verifies tenant_id-to-adapter binding on every load to prevent adapter-swap bugs from leaking one tenant’s fine-tuned behavior to another’s requests.
- Alternative: shared training data lake with row-level tenant_id filtering.
- Trade-off: row-level filtering is cheaper to build but one query/ETL bug away from a serious cross-tenant data leak (a compliance-critical failure mode for enterprise SaaS); physical/key-level isolation costs more in engineering and operational overhead (key management, per-tenant IAM policies) but is what enterprise security reviews and most contractual DPAs actually require.
-
Base model tiering vs. one universal base model.
- Chosen: offer 2–3 base model tiers (e.g., 8B “standard” and 70B “premium”), all tenants fine-tune against one of these fixed bases; platform does not let tenants bring arbitrary custom base architectures.
- Trade-off: constrains tenant flexibility, but is essential for the multi-LoRA batching trick to work at all — batched adapter serving requires all co-batched requests to share the same base model architecture and weights; supporting arbitrary bases per tenant would force per-tenant dedicated serving, reintroducing the cost problem decision #1 was meant to solve.
Scale Math
- 400 tenants, aggregate 5,000 QPS peak, Zipfian: top 20 tenants ≈ 3,500 QPS (70%), next 80 tenants ≈ 1,250 QPS (25%), remaining 300 tenants ≈ 250 QPS combined (5%, <1 QPS each).
- Adapter storage: 360 LoRA tenants × avg 100MB = 36GB in blob storage (trivial); 40 full-fine-tune tenants × 14GB (7B fp16) = 560GB, or if on 70B tier, 40 × 140GB = 5.6TB — full-fine-tune tier storage cost is why it’s priced as premium.
- GPU sizing for standard 8B tier: assume one A100-80GB serves base model (~16GB in fp16) + KV cache + ~30-50 resident LoRA adapters (100MB × 50 = 5GB) + activation memory, leaving room for a batch of ~64-128 concurrent sequences. At ~40 tokens/sec/sequence generation with continuous batching achieving ~2,000-4,000 tokens/sec aggregate throughput per GPU, one node handles roughly 50-100 concurrent streaming requests. To sustain 3,500 QPS on the hot tier (assuming average request needs ~2 sec of GPU time end-to-end including queuing), you need concurrency ≈ 3,500 × 2s = 7,000 concurrent in-flight requests → roughly 70-140 GPU nodes for the hot tier alone, horizontally scaled with the fairness scheduler distributing tenants across nodes (with hot tenants possibly pinned to dedicated node pools).
- Cache sizing: host RAM warm tier for ~400 adapters × 150MB avg = 60GB per cache-serving host — comfortably fits a single high-memory host, replicated across AZs.
- Cold-start adapter load penalty: 50-150ms from blob storage; at long-tail QPS (<1 QPS per tenant) this is an acceptable, infrequent tax, not a steady-state cost.
Failure Modes & How They’re Handled
- Adapter cache thrash under traffic shift: if traffic pattern shifts (yesterday’s cold tenant suddenly spikes), LRU eviction causes repeated cold loads. Mitigated with predictive pre-warming from usage-metering signals (detect ramping QPS, proactively pull adapter into hot cache) and by rate-limiting new-tenant burst traffic while cache warms.
- Noisy neighbor despite fair queuing: a misbehaving tenant script retries aggressively on errors, amplifying load. Mitigated with per-tenant circuit breakers at the gateway (429 with backoff hints once quota exceeded) independent of the fairness scheduler, so bad behavior is stopped before it reaches the GPU pool at all.
- Cross-tenant data leak via serving bug: a routing bug loads the wrong adapter for a tenant_id. Mitigated by cryptographic tenant_id-to-adapter-checksum binding validated per request, plus canary requests with known fingerprints run continuously against production routing to detect misrouting, plus mandatory adapter output audit logging tied to tenant_id for post-incident forensics.
- Base model version drift breaking adapters: platform upgrades the shared base model; existing LoRA adapters were trained against old weights and become incompatible or degrade silently. Mitigated by treating base model versions as immutable, versioned artifacts; new base versions are opt-in per tenant, requiring re-training/re-validation of adapters, with the old base version kept serving until migration completes (blue/green at the base-model level).
- Training job data leakage between tenants on shared training cluster: a bug in job scheduling co-mingles data batches. Mitigated by strict namespace/network-policy isolation per training job pod (no shared PVC), and a mandatory data-lineage checksum comparing training-input hash to the tenant’s declared source bucket before the resulting adapter is registered.
- GPU node failure mid-batch: in-flight requests across many tenants on that node fail simultaneously. Mitigated by stateless serving nodes behind the router (no session affinity beyond adapter cache warmth), fast node health-check eviction, and client-side retry with idempotency keys; router re-routes to next node which pulls the needed adapter (cache miss penalty absorbed).
Interviewer Follow-Up Q&A
Q: How would you support a tenant who insists on a fully dedicated, isolated deployment for regulatory reasons (e.g., government contract)? A: Treat it as a distinct SKU/tier outside the shared multi-LoRA pool — a dedicated node pool (or even dedicated cluster) running only that tenant’s merged model, priced to reflect real dedicated-GPU cost. The control plane and adapter registry stay shared for operational consistency (same CI/CD, same eval harness), but the data plane (serving + potentially training compute) is physically isolated. This is a standard “shared core, isolated edge” pattern for tenants with compliance requirements the shared pool cannot satisfy.
Q: What happens when two tenants’ concurrent requests land in the same GPU batch — could tenant B’s activations influence tenant A’s output? A: No, if implemented correctly: batched multi-LoRA kernels apply the adapter delta as a per-row operation within the batch (each sequence’s hidden states are only ever combined with that sequence’s own LoRA A/B matrices before the matmul), and attention is computed per-sequence, not across the batch dimension for content — batching only shares underlying base-weight reads, not any tenant’s data or intermediate activations. This is the same isolation guarantee any multi-tenant batched inference system (even single-adapter) already relies on; it needs to be validated with unit tests that assert output invariance to what else is in the batch.
Q: How do you decide when a tenant should be moved from best-effort shared tier to a guaranteed-capacity tier? A: Usage-based auto-promotion: track sustained QPS and p99 latency-vs-SLA violations per tenant over a rolling window; once a tenant crosses a threshold (e.g., consistently >X QPS or repeated SLA breaches attributable to contention), trigger a billing-tier upgrade conversation and provision dedicated/reserved capacity. This is both a technical (capacity planning) and product (upsell) trigger, and should be instrumented as a first-class metric, not discovered via customer complaints.
Q: How would you validate that a newly fine-tuned adapter is actually safe/good before it goes to production traffic? A: An automated eval gate in the fine-tuning orchestrator: run the candidate adapter against (a) a tenant-agnostic safety/toxicity/PII-leak test suite, (b) a tenant-specific held-out validation set if provided, and © regression checks against the previous adapter version’s known-good outputs. Only adapters passing thresholds get promoted to the registry’s “servable” state; failures route to a human review queue. This mirrors CI/CD gating but for model artifacts instead of code.
Q: Your top-20 hot tenants generate 70% of traffic — why not just give them dedicated capacity and simplify the rest of the system? A: That’s a valid alternative and often what’s actually done in practice — a hybrid: dedicated/pinned node pools for the top N tenants (removing them from multi-tenant contention entirely and simplifying their SLA story), while the long tail of 300+ low-QPS tenants still shares the multi-LoRA pool where the batching/caching economics matter most. The interesting engineering (multi-LoRA batching, fairness scheduling) is precisely for that long tail, where dedicating a GPU per tenant would be wasteful.