Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Zero-downtime deployment pattern
📖 Scenario: You are managing a web application hosted on a cloud provider. To avoid downtime during updates, you want to deploy a new version of your application alongside the old one, then switch traffic to the new version only after it is ready.
🎯 Goal: Build a Terraform configuration that creates two identical instances of a web server behind a load balancer. The load balancer should route traffic only to the active instance. You will configure the infrastructure to allow switching traffic from the old instance to the new instance without downtime.
📋 What You'll Learn
Create two compute instances with the same configuration but different names
Create a load balancer with a target group
Attach only one instance to the load balancer target group at a time
Add a variable to select which instance is active
Use the variable to control which instance receives traffic
💡 Why This Matters
🌍 Real World
Zero-downtime deployment is critical for web applications that must remain available during updates. This pattern is used in production environments to avoid service interruptions.
💼 Career
Cloud engineers and DevOps professionals use zero-downtime deployment patterns to ensure high availability and reliability of applications during updates.
Progress0 / 4 steps
1
Create two compute instances
Create two AWS EC2 instances named app_instance_old and app_instance_new with the AMI ID ami-0c55b159cbfafe1f0 and instance type t2.micro.
Terraform
Hint
Use two aws_instance resources with the specified AMI and instance type. Name them exactly app_instance_old and app_instance_new.
2
Create a load balancer and target group
Add an AWS Application Load Balancer resource named app_lb and a target group named app_tg with port 80 and protocol HTTP.
Terraform
Hint
Use aws_lb for the load balancer and aws_lb_target_group for the target group. Use port 80 and HTTP protocol.
Note: Replace subnet and VPC IDs with your actual values.
3
Add a variable to select the active instance
Create a Terraform variable named active_instance of type string with default value "old" to select which instance receives traffic.
Terraform
Hint
Define a variable block named active_instance with type string and default value "old".
4
Attach only the active instance to the target group
Create an aws_lb_target_group_attachment resource named active_attachment that attaches the instance selected by var.active_instance to the target group aws_lb_target_group.app_tg. Use a conditional expression to select aws_instance.app_instance_old.id if var.active_instance is "old", else aws_instance.app_instance_new.id.
Terraform
Hint
Use a conditional expression for target_id to select the instance ID based on var.active_instance.
Practice
(1/5)
1. What is the main goal of a zero-downtime deployment in Terraform?
easy
A. Manually switch traffic after deployment
B. Update applications without stopping them or causing downtime
This means at least 75% of current tasks must stay healthy and running during deployment.
Step 2: Interpret deployment_maximum_percent
This allows up to 200% of the desired tasks to run temporarily, enabling new tasks to start before old ones stop.
Final Answer:
At least 75% of tasks stay running; up to 200% tasks can run temporarily -> Option D
Quick Check:
Min healthy 75%, max 200% = safe rolling update [OK]
Hint: Min healthy % keeps tasks running; max % allows extra tasks [OK]
Common Mistakes:
Thinking percentages mean exact task counts
Assuming deployment stops tasks before starting new ones
Confusing min and max percentages
4. You set deployment_minimum_healthy_percent = 100 and deployment_maximum_percent = 100 in Terraform for ECS service. What issue will this cause?
medium
A. Deployment will run twice the desired tasks temporarily
B. Deployment will succeed with zero downtime
C. Deployment will fail because no new tasks can start before old ones stop
D. Deployment will ignore these settings and use defaults
Solution
Step 1: Analyze min and max percent both at 100%
Min healthy 100% means all old tasks must stay running; max 100% means no extra tasks can start.
Step 2: Understand deployment impact
New tasks cannot start until old ones stop, but old ones cannot stop because min healthy is 100%, causing deployment to fail.
Final Answer:
Deployment will fail because no new tasks can start before old ones stop -> Option C
Quick Check:
Min 100% + Max 100% blocks rolling update [OK]
Hint: Min 100% and Max 100% blocks task replacement [OK]
Common Mistakes:
Assuming deployment will succeed without downtime
Thinking max 100% allows extra tasks
Ignoring min healthy effect on stopping old tasks
5. You want to deploy a new version of your app with zero downtime using Terraform ECS service. Your desired task count is 4. Which configuration best supports zero-downtime deployment?
hard
A. deployment_minimum_healthy_percent = 75 deployment_maximum_percent = 125
B. deployment_minimum_healthy_percent = 100 deployment_maximum_percent = 100
C. deployment_minimum_healthy_percent = 50 deployment_maximum_percent = 150
D. deployment_minimum_healthy_percent = 0 deployment_maximum_percent = 200
Solution
Step 1: Evaluate each option for zero-downtime support
deployment_minimum_healthy_percent = 50 deployment_maximum_percent = 150 allows only 50% healthy tasks, risking downtime. deployment_minimum_healthy_percent = 100 deployment_maximum_percent = 100 blocks new tasks starting before old stop. deployment_minimum_healthy_percent = 0 deployment_maximum_percent = 200 allows zero healthy tasks, risking downtime. deployment_minimum_healthy_percent = 75 deployment_maximum_percent = 125 keeps 75% healthy and allows 125% max tasks, enabling smooth rolling update.
Step 2: Choose best balance for zero-downtime
deployment_minimum_healthy_percent = 75 deployment_maximum_percent = 125 ensures enough healthy tasks remain while allowing new tasks to start before old stop, supporting zero downtime.
Final Answer:
deployment_minimum_healthy_percent = 75 and deployment_maximum_percent = 125 -> Option A
Quick Check:
Min healthy 75% + max 125% = safe rolling update [OK]
Hint: Min healthy ~75% and max ~125% enable zero downtime [OK]