Skip to content

Latest commit

 

History

History

high-availability

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Make the App Survive Server Failure

Level: Intermediate
Estimated time: 2 weeks
Skills: Terraform, VPC design, load balancing, auto scaling, image baking with Packer, rolling deployments, monitoring
AWS services: Amazon VPC, Amazon EC2, EC2 Auto Scaling, Elastic Load Balancing (Application Load Balancer), Amazon RDS, AWS Systems Manager Session Manager, Amazon CloudWatch, Amazon SNS, AWS IAM, AWS Secrets Manager

Background

ShopNest runs its storefront on a single Amazon EC2 instance in a public subnet. Last week that instance became unresponsive after a failed OS update, and the site was down for several hours on a weekday afternoon. Customers could not check out, the support team was flooded with tickets, and the on-call engineer had to rebuild the server by hand from memory.

The post-incident review found that nothing about the setup could survive the loss of one machine. Leadership has asked the platform team to remove the single point of failure before the next sales campaign.

Findings from the post-incident review:

  1. One EC2 instance serves all traffic. If it stops, the site stops.
  2. The instance has a public IP, and port 22 is open to the internet for admin access.
  3. The database runs on the same instance, so a server failure also risks data loss.
  4. The server was configured by hand. Nobody can rebuild it the same way twice.
  5. There were no alarms. The outage was reported by a customer on social media.

Your task

Design and build a highly available version of the ShopNest storefront on AWS using Terraform. The app must run on multiple instances across two Availability Zones behind a load balancer, recover automatically from instance failure, and be deployable without downtime. You must prove, with evidence, that terminating an instance does not take the site down.

Before you start

  • A sandbox AWS account with an AWS Budgets alert. A domain is optional (HTTPS listener); the brief allows HTTP for the demo.
  • Terraform 1.11 or newer, Packer, the AWS CLI and the Session Manager plugin.
  • Finish Remove SSH Access to Servers first, or know Session Manager already.
  • Comfortable with: VPC design, security groups, a small web app that talks to a database.

Suggested milestones

  • Week 1, days 1 to 2: VPC, subnets, NAT or endpoints, remote state.
  • Week 1, days 3 to 5: Packer AMI, launch template with IMDSv2, ASG across two AZs, ALB with health check path.
  • Week 2, days 1 to 2: RDS Multi-AZ, Secrets Manager, app reads the secret.
  • Week 2, days 3 to 4: alarms, dashboard, scaling policy, instance refresh test, termination test, failover test.
  • Week 2, day 5: runbook, evidence, teardown, then open change-request.md.

Milestones are a pacing guide, not extra requirements. Record the date you reach each one; it makes a better story for your README and your interviews.

Current state

  • One EC2 instance in a public subnet with a public IP and an Elastic IP.
  • Security group allows inbound 22 and 80 from 0.0.0.0/0.
  • App and database (installed locally on the instance) share the same server.
  • Admins connect with a shared SSH key stored on a team laptop.
  • No infrastructure as code, no golden image, no monitoring or alarms.
  • Deployments are done by SSH, git pull, and a service restart.

Target architecture

Make the App Survive Server Failure architecture

The Application Load Balancer is the only component in the public subnets. App instances run in private subnets in an Auto Scaling Group spread over two Availability Zones and are launched from a golden AMI built with Packer. The database moves to Amazon RDS with Multi-AZ enabled, reachable only from the app tier. Engineers reach instances through Session Manager, never SSH.

Requirements

Networking

  • One VPC with at least two public and two private subnets, spread across two Availability Zones.
  • Public subnets contain only the ALB (and NAT gateways if you use them). No EC2 instance has a public IP.
  • Private app instances must reach the services they need (SSM, package repositories if required) through NAT gateways or VPC endpoints. Document which option you chose and why.
  • RDS uses a DB subnet group made of private subnets only.

Compute and image

  • Build a golden AMI with Packer that contains the app, its runtime, and the SSM Agent. The AMI build must be repeatable from code in the repo.
  • Use a launch template that references the golden AMI. Require IMDSv2 on the launch template.
  • Run app instances in an Auto Scaling Group with a minimum of 2 instances across both AZs.
  • Configure the ASG health check type to use the ALB (ELB) health checks, not only EC2 status checks.
  • Use instance refresh to roll out a new AMI or launch template version with a minimum healthy percentage that keeps the site serving traffic.

Load balancing

  • Internet-facing ALB in the public subnets with a target group pointing at the ASG.
  • A dedicated health check path (for example /health) that returns 200 only when the app is ready to serve.
  • HTTPS listener with an ACM certificate if you have a domain. If you do not, document this as a known gap and use HTTP for the demo only.

Database

  • Amazon RDS (MySQL or PostgreSQL) with Multi-AZ enabled, storage encryption on, and no public access.
  • Database credentials stored in AWS Secrets Manager (RDS managed master password is acceptable). No passwords in Terraform variables, user data, or the AMI.
  • Automated backups enabled with a retention period you can justify.

Security

  • App security group allows inbound app traffic only from the ALB security group.
  • Database security group allows inbound database traffic only from the app security group.
  • No security group allows inbound port 22 from anywhere.
  • Instance profile with the AmazonSSMManagedInstanceCore policy (or equivalent) plus only the extra permissions the app needs, such as reading its one secret.

Scaling and monitoring

  • Target tracking scaling policy on the ASG (for example average CPU or ALB request count per target). Document the target value and why.
  • CloudWatch alarms, sent to an SNS topic with an email subscription, for at least:
    • ALB target group unhealthy host count above 0 for a sustained period.
    • ALB 5XX error count above a threshold you define.
    • RDS CPU or free storage space crossing a threshold you define.
  • A simple CloudWatch dashboard showing healthy hosts, request count, target response time, and ASG instance count.

Infrastructure as code

  • All AWS resources are created with Terraform. Remote state in Amazon S3 with locking (Terraform 1.11 or newer, use_lockfile = true).
  • Organize Terraform into modules or clear files (network, compute, database, monitoring).

Acceptance criteria

  • terraform plan on a clean checkout shows no changes after apply.
  • No EC2 instance in the account has a public IP, and no security group allows inbound 22 (screenshot or CLI output).
  • ALB target group shows at least 2 healthy targets in different Availability Zones.
  • While a request loop hits the site every second, you terminate one app instance. The site keeps responding, any failed requests are recorded and explained, and the ASG launches a replacement that becomes healthy (log output plus ASG activity history).
  • You connect to an app instance through Session Manager and show the session in the console or CLI.
  • An RDS reboot with failover completes and the app reconnects without manual changes (evidence of the failover event and app responses).
  • A new AMI version is rolled out with instance refresh while the request loop shows the site staying up.
  • A load test or CPU stress causes the target tracking policy to scale out, then scale back in (ASG activity history).
  • At least one CloudWatch alarm fires and the SNS email is received (screenshot).
  • No database password appears in the repo, Terraform state outputs, user data, or AMI.

Constraints

  • Terraform only for AWS resources. No manual console changes except for viewing.
  • No SSH keys on instances and no inbound port 22.
  • No long-lived AWS access keys committed anywhere. If you add CI/CD, use GitHub Actions with OIDC.
  • Use a single AWS Region with two Availability Zones.
  • Instances must be replaceable at any time. Nothing important may live only on an instance's local disk.

Out of scope

  • Multi-region failover and Route 53 health-check routing.
  • Containers (Amazon ECS or Amazon EKS).
  • Caching layers such as Amazon ElastiCache or Amazon CloudFront.
  • Full CI/CD for the application code (a manual Packer build plus instance refresh is enough).

Mid-sprint change request

In a real job, requirements change while you are building. This project has one change request. It is stored in change-request.md in this folder.

Do not read it until you have finished the main requirements (the last milestone above says when). Opening it early removes the point of the exercise, which is adapting a finished design to a new requirement.

Deliverables

  1. A Git repository with Terraform code, the Packer template, and the app (or a link to the app source).
  2. An architecture diagram, updated to match what you built.
  3. A README explaining design decisions: NAT versus VPC endpoints, health check settings, scaling targets, instance refresh settings.
  4. An evidence folder with screenshots or CLI output for every acceptance criterion.
  5. A short demo video (5 minutes or less) showing the instance termination test with the site staying up.
  6. A runbook for the on-call engineer: how to roll out a new AMI and how to roll back.

Definition of done

  • Pull request reviewed by at least one peer or mentor, or a completed self-review committed to the repository.
  • Every acceptance criterion has evidence linked in the README.
  • Runbook and design notes are written.
  • All resources are destroyed after the demo and the teardown is confirmed.

Cost and cleanup

  • Billed hourly while running: the Application Load Balancer, NAT gateways, any interface VPC endpoints, EC2 instances, and the RDS instance (Multi-AZ runs a standby, so you pay for two DB instances).
  • Billed by usage: EBS volumes and snapshots, RDS storage and backups, data transfer, CloudWatch alarms and logs, Secrets Manager secrets.
  • Old AMIs and their EBS snapshots keep costing money after the instances are gone. Deregister them and delete the snapshots.
  • Document the teardown steps in the README and run terraform destroy after the demo. Confirm in the console that no ALB, NAT gateway, RDS instance, or EC2 instance remains.

Where to read

Official documentation only. If a tool behaves differently from what this brief says, the documentation wins; open an issue so the brief can be corrected.

Resume bullet

Replaced a single-server e-commerce deployment with a Terraform-managed, multi-AZ architecture (ALB, Auto Scaling Group with Packer golden AMIs, RDS Multi-AZ, SSM-only access), and proved zero customer-facing downtime during instance termination and rolling AMI updates. Replace the claims and numbers with your own measured results, such as how long the replacement instance took to become healthy.

Interview questions to prepare

  1. Why does the ASG use ELB health checks instead of only EC2 status checks? What happens if the health check path is wrong?
  2. How does instance refresh decide how many instances to replace at once, and how would you roll back a bad AMI?
  3. What happens during an RDS Multi-AZ failover, and what must the application do to reconnect?
  4. How do your private instances reach Systems Manager without public IPs, and what are the cost trade-offs of NAT gateways versus VPC endpoints?
  5. Why did you pick your target tracking metric and target value? What would make it scale too late?
  6. What would you still need to change to survive the loss of a whole AWS Region?

Part of Real DevOps Projects. Build it, push it to your own GitHub, and add it to your resume. Use the evidence template, the demo video guide and the self-review checklist.