Multi-tenancy and isolation in MLOps - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When managing multiple users or teams on the same system, it's important to understand how the system's work grows as more tenants are added.
We want to know how the system handles tasks for many tenants without slowing down too much.
Analyze the time complexity of the following code snippet.
for tenant in tenants:
isolate_environment(tenant)
for job in tenant.jobs:
run_job(job)
log_results(job)
This code runs jobs for each tenant separately, isolating their environments and logging results.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Running jobs inside each tenant's isolated environment.
- How many times: For each tenant, all their jobs are processed one by one.
As the number of tenants and their jobs increase, the total work grows by adding all jobs from all tenants.
| Input Size (tenants * jobs) | Approx. Operations |
|---|---|
| 10 tenants with 5 jobs each | 50 operations |
| 100 tenants with 5 jobs each | 500 operations |
| 100 tenants with 50 jobs each | 5,000 operations |
Pattern observation: The total work grows proportionally with the total number of jobs across all tenants.
Time Complexity: O(n * m)
This means the time grows in proportion to the number of tenants (n) times the number of jobs per tenant (m).
[X] Wrong: "Adding more tenants won't affect the time much because jobs run independently."
[OK] Correct: Even if jobs run separately, the system still processes all jobs for all tenants, so total time grows with total jobs.
Understanding how work scales with tenants and jobs helps you design systems that stay efficient as more users join.
"What if jobs for all tenants could run in parallel? How would that change the time complexity?"
Practice
Solution
Step 1: Understand multi-tenancy concept
Multi-tenancy means many users share one system but remain separate and safe.Step 2: Identify the correct purpose
The goal is to let users share resources without interfering with each other.Final Answer:
To allow multiple users to share the same system safely -> Option CQuick Check:
Multi-tenancy = safe shared use [OK]
- Confusing multi-tenancy with faster hardware use
- Thinking all data is mixed without separation
- Believing only one user runs at a time
Solution
Step 1: Identify resource for tenant isolation
Kubernetes namespaces isolate resources per tenant.Step 2: Match correct YAML kind
Namespace kind with tenant name isolates tenant data correctly.Final Answer:
apiVersion: v1 kind: Namespace metadata: name: tenant-a -> Option BQuick Check:
Namespace = tenant isolation [OK]
- Choosing Pod or Service which do not isolate tenants
- Confusing ConfigMap with isolation resource
- Missing correct YAML syntax for namespaces
tenants = {"tenant1": {"models": ["modelA"]}, "tenant2": {"models": ["modelB"]}}
for tenant, data in tenants.items():
print(f"{tenant} has models: {', '.join(data['models'])}")Solution
Step 1: Understand dictionary structure
Each tenant key maps to a dict with a 'models' list.Step 2: Loop and print models per tenant
Loop prints tenant name and joins model names correctly.Final Answer:
tenant1 has models: modelA tenant2 has models: modelB -> Option AQuick Check:
Correct tenant-model mapping printed [OK]
- Swapping models between tenants
- Printing empty model lists
- Mistyping keys causing KeyError
apiVersion: v1
kind: Namespace
metadata:
name: tenant1
---
apiVersion: v1
kind: Pod
metadata:
name: tenant1-pod
namespace: tenant2
spec:
containers:
- name: app
image: ml-app:latest
What is the main issue here?Solution
Step 1: Check namespace assignment
Pod metadata namespace is 'tenant2' but tenant namespace defined is 'tenant1'.Step 2: Identify isolation problem
Pod runs in wrong namespace, breaking tenant isolation.Final Answer:
Pod is assigned to a different namespace than tenant's namespace -> Option AQuick Check:
Namespace mismatch breaks isolation [OK]
- Ignoring namespace mismatch
- Assuming image name causes error
- Thinking missing ports cause isolation failure
Solution
Step 1: Understand isolation requirements
Tenant data must be separated and access controlled to prevent leaks.Step 2: Identify best isolation methods
Namespaces isolate resources; RBAC controls who can access what.Step 3: Evaluate options
Only Use separate namespaces for each tenant and enforce RBAC policies limiting access uses both namespaces and RBAC for strong isolation.Final Answer:
Use separate namespaces for each tenant and enforce RBAC policies limiting access -> Option DQuick Check:
Namespaces + RBAC = strong tenant isolation [OK]
- Relying only on application code for data separation
- Sharing service accounts across tenants
- Ignoring resource limits and node sharing risks
