Blue-green deployment for models in MLOps - Time & Space Complexity
We want to understand how the time to switch between two model versions grows as the size of the model or traffic increases.
How does the deployment process scale when moving from one model to another?
Analyze the time complexity of the following deployment switching code.
# Assume models are deployed in two environments: blue and green
# Switch traffic from blue to green
def switch_traffic(traffic_router, green_model_endpoint):
# Update routing rules to point to green model
for user in traffic_router.users:
traffic_router.route[user] = green_model_endpoint
return "Switched to green model"
This code switches user traffic routing from the blue model to the green model by updating routing rules for each user.
Look for loops or repeated steps in the code.
- Primary operation: Loop over all users to update routing.
- How many times: Once per user in the traffic router.
As the number of users grows, the time to update routing grows too.
| Input Size (n users) | Approx. Operations |
|---|---|
| 10 | 10 updates |
| 100 | 100 updates |
| 1000 | 1000 updates |
Pattern observation: The time grows directly with the number of users; doubling users doubles the work.
Time Complexity: O(n)
This means the time to switch models grows linearly with the number of users to update.
[X] Wrong: "Switching traffic is instant and does not depend on user count."
[OK] Correct: Each user's routing must be updated, so more users mean more updates and more time.
Understanding how deployment time scales helps you design smoother model updates and shows you think about real-world system behavior.
"What if the routing update was done in batches instead of per user? How would the time complexity change?"