No history yet

Resilient Compute Architectures

Strategically Placing Your Instances

You already know how to launch an EC2 instance, but where does it physically live? By default, AWS decides. For resilient architectures, you need more control. This is where EC2 Placement Groups come in. They're a way to influence the physical placement of your instances within an Availability Zone (AZ) to meet specific performance or availability needs.

There are three types of placement groups:

  • Cluster: Packs instances close together inside an AZ. This strategy is all about minimizing network latency for high-performance computing (HPC) workloads where instances need to communicate rapidly.
  • Spread: Places each instance on distinct underlying hardware. Think of it as putting your eggs in different baskets within the same AZ. This minimizes the impact if a single piece of hardware fails. It's ideal for critical applications where the failure of one instance shouldn't affect others, like a small group of database servers.
  • Partition: Divides instances into logical segments called partitions, and each partition runs on its own rack of hardware. This gives you visibility into the underlying hardware. It's a good middle ground, useful for large distributed workloads like Hadoop or Cassandra, where you want to isolate failures to a single partition while keeping related data relatively close.

Choosing the right placement group is a trade-off. A Cluster group gives you the best network performance but concentrates your failure risk. A Spread group maximizes availability within an AZ but might have slightly higher latency between instances. A Partition group balances these concerns for large, rack-aware applications.

Automating Resilience and Scale

Manually adding or removing servers is slow and inefficient. This is why Auto Scaling Groups (ASGs) are fundamental to resilient architectures. An ASG's job is to maintain a desired number of instances, automatically replacing any that fail health checks and scaling the fleet in or out based on demand.

To configure an ASG, you need a blueprint for new instances. Historically, this was a Launch Configuration. However, Launch Configurations are immutable; you can't edit them. To make a change, you have to create a new one and update the ASG. The modern approach is to use Launch Templates, which are versionable. You can create new versions of a template with updated parameters (like a new AMI or instance type) and configure the ASG to use the new version for future launches. Always prefer Launch Templates over Launch Configurations.

Key takeaway: Launch Templates are versionable and more flexible. Launch Configurations are the legacy, immutable option.

The real power of ASGs comes from their dynamic scaling policies, which adjust the number of instances automatically.

  • Target Tracking: This is the simplest and most common policy. You set a target for a specific metric, like "keep average CPU utilization at 50%." The ASG then automatically adds or removes instances to keep the metric at or near your target.
  • Step Scaling: This policy provides more granular control. You define steps based on CloudWatch alarm thresholds. For example, if CPU utilization exceeds 70%, add two instances. If it exceeds 90%, add four more. This allows for a more aggressive response to large, sudden spikes in traffic.
  • Scheduled Scaling: This is for predictable traffic patterns. If you know your application traffic always spikes at 9 AM on weekdays, you can schedule a scaling action to increase capacity at 8:45 AM and then scale back down in the evening.

Distributing Traffic Intelligently

Having multiple instances is great for resilience, but you need a way to distribute incoming traffic across them. That's the role of Elastic Load Balancing (ELB). ELB acts as a single point of contact for clients and routes requests to healthy EC2 instances in one or more Availability Zones. AWS offers several types of load balancers, and choosing the right one is critical.

Load BalancerLayerUse CaseProtocol
Application (ALB)7 (Application)HTTP/HTTPS traffic, microservices, container-based apps.HTTP, HTTPS, gRPC
Network (NLB)4 (Transport)Extreme performance, TCP/UDP traffic, static IP addresses.TCP, UDP, TLS
Gateway (GLB)3 (Network)Distributing traffic to a fleet of virtual security appliances.IP

For most web applications, the Application Load Balancer is the right choice. It operates at the application layer, meaning it can inspect HTTP headers and route traffic based on the content of the request, such as the URL path. This is called path-based routing and is perfect for microservice architectures where /api/users goes to one set of servers and /api/products goes to another.

The Network Load Balancer is built for speed. It operates at the transport layer and can handle millions of requests per second with ultra-low latency. It's ideal for TCP-heavy workloads like gaming servers or financial trading platforms. It also provides a static IP address for your application, which can be a requirement for some legacy systems.

Gateway Load Balancers are a specialized tool for inserting virtual appliances, like firewalls or intrusion detection systems, into the network path without making complex routing changes.

Use Elastic Load Balancing (ELB) to distribute incoming traffic evenly across multiple EC2 instances and AZs, ensuring that your application can handle traffic spikes without any disruption.

To ensure ELB only sends traffic to healthy instances, it uses health checks. These are regular pings to a specific port or path on your instances. If an instance fails consecutive health checks, the ELB stops sending it traffic until it becomes healthy again.

When scaling in, you don't want to abruptly terminate an instance that's in the middle of handling a request. This is where connection draining (or deregistration delay for ALBs/NLBs) comes in. It tells the load balancer to stop sending new requests to an instance marked for termination, but to allow it time to finish handling any in-flight requests before it's shut down. This prevents errors and ensures a smooth user experience.

Optimizing for Cost and Resilience

Running a highly available architecture doesn't have to be expensive. AWS provides several pricing models, and mixing them strategically is key to cost optimization.

  • On-Demand: You pay for compute by the second with no long-term commitment. It's flexible but the most expensive option. Best for unpredictable workloads.
  • Savings Plans & Reserved Instances (RIs): You commit to a certain amount of compute usage for a 1 or 3-year term in exchange for a significant discount compared to On-Demand prices. Great for your baseline, predictable workload.
  • Spot Instances: These are spare EC2 capacity that AWS offers at a huge discount—up to 90% off On-Demand prices. The catch is that AWS can reclaim this capacity with just a two-minute warning. are perfect for fault-tolerant workloads like batch processing, data analysis, or even web fleets if you design your architecture to handle interruptions.
Lesson image

To build a truly cost-optimized and resilient architecture, you can configure your Auto Scaling Group to use a mix of purchasing options. For example, you can specify that your ASG should fulfill 50% of its capacity with On-Demand instances to ensure a stable baseline, and the other 50% with Spot Instances to save money. If Spot capacity becomes unavailable, the ASG can automatically launch On-Demand instances to maintain the desired capacity.

Let's test your understanding of these advanced architectural patterns.

Quiz Questions 1/6

Your company runs a High-Performance Computing (HPC) cluster for complex simulations. The most critical requirement is the lowest possible network latency between instances. Which EC2 Placement Group strategy should you use?

Quiz Questions 2/6

When configuring an Auto Scaling Group, what is the modern, versionable, and recommended method for defining the EC2 instances it should launch?

By mastering these concepts—placement groups, advanced auto-scaling, intelligent load balancing, and strategic cost optimization—you can design compute architectures on AWS that are not only scalable but truly resilient to failure.