2.2.1.5. Microservices and Containers: ECS, EKS, Fargate
2.2.1.5. Microservices and Containers: ECS, EKS, Fargate
💡 First Principle: Microservices and containers break applications into small, independently deployable units, enhancing agility, scalability, and resilience by isolating components.
Microservices and containers break applications into small, independently deployable units, enhancing agility, scalability, and resilience by isolating components.
Microservices is an architectural approach where a large application is built as a suite of small services that run independently and communicate over well-defined APIs. Containers (like Docker) are a technology for packaging these microservices and their dependencies into isolated, portable units.
AWS provides robust container orchestration services:
- Amazon ECS (Elastic Container Service): A fully managed container orchestration service that makes it easy to run, stop, and manage Docker containers on a cluster. An AWS-native container orchestration service for running Docker containers on a managed cluster of EC2 instances or Fargate. Ideal for microservices and batch jobs, with deep AWS integration.
- Amazon EKS (Elastic Kubernetes Service): A fully managed Kubernetes service that makes it easy to run Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane. A managed Kubernetes service for deploying, managing, and scaling containerized applications. Provides advanced orchestration for existing or new Kubernetes workloads.
- AWS Fargate: A serverless compute engine for containers that works with both ECS and EKS. It eliminates server provisioning/management, allowing focus on application development. Perfect for high agility and minimal operational overhead.
Key Concepts of Microservices & Containers:
- "Microservices": Small, independent, loosely coupled services.
- "Containers": Portable, isolated application packages (e.g., Docker). To containerize an existing application, first write a Dockerfile (base image, dependencies, start command), build the image from it, push the image to Amazon ECR, then run it on ECS or EKS (on EC2 or Fargate) — every later step depends on that image.
- "Orchestration (ECS/EKS)": Manages container deployment, scaling, networking.
- "Serverless Containers (Fargate)": No server management.
- "Why containers": An image bundles code with its libraries and runtime, so it runs the same on a laptop, in test and in production, and each microservice can be deployed and scaled independently. Containers share the host's kernel, so a workload that needs a custom kernel or direct hardware access belongs on EC2 (including bare metal instances).
- "Service discovery (AWS Cloud Map)": Instances and tasks are replaced constantly and their IPs change, so services register in a registry such as AWS Cloud Map (used by ECS service discovery) and clients look a service up by name to get its current IP and port — never hardcode addresses.
- "Circuit breaker pattern": When a downstream service is failing or slow, the caller stops calling it for a cool-down period and fails fast (or returns a fallback) instead of holding connections and exhausting threads, so one failure does not cascade upstream. Contrast: the Saga pattern coordinates a multi-service transaction with compensating actions, and the Strangler Fig pattern incrementally replaces a monolith.
Scenario: Imagine an e-commerce platform where product catalog, order processing, and user authentication are separate containerized microservices, deployed and automatically scaled using Amazon ECS on AWS Fargate.
Visual: Container Orchestration Options
⚠️ Common Pitfall: Choosing a full Kubernetes solution (EKS) for a simple application with only a few containers. This introduces unnecessary operational complexity. ECS on Fargate is usually simpler — note that Fargate itself is not standalone; it is a compute engine that must run through ECS or EKS as the orchestrator, it cannot run containers on its own.
Key Trade-Offs:
- Simplicity (Fargate) vs. Control (EC2 with ECS/EKS): Fargate provides serverless simplicity but less control over the underlying compute. Running ECS/EKS on EC2 gives more control but adds server management overhead.
- AWS Native (ECS) vs. Open Standard (EKS): ECS integrates deeply with AWS services. EKS offers Kubernetes, providing portability and a large community but can be more complex.
Reflection Question: How do microservices and containers, orchestrated by services like ECS or EKS (especially with Fargate), fundamentally change application architecture and operational management by promoting agility, scalability, and resilience?