Multi-tenancy and isolation in MLOps - Time & Space Complexity
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?"