AWS Architecture & Services Deep Dive

AWS Compute Services: EC2, Lambda, ECS & EKS

4 min read

Compute service selection is one of the most common interview topics. Understanding when to use each service demonstrates architectural maturity.

EC2: The Foundation

Instance Types & Selection

Family Use Case Example
General Purpose (M/T) Web servers, small DBs m7i.xlarge, t3.medium
Compute Optimized (C) Batch processing, gaming c7i.2xlarge
Memory Optimized (R/X) In-memory databases r7i.4xlarge, x2idn.large
Storage Optimized (I/D) Data warehousing, HDFS i4i.large, d3.xlarge
Accelerated (P/G) ML training, graphics p5.48xlarge, g5.xlarge

Interview Question: Right-sizing

Q: "Your web application uses m5.2xlarge instances but CPU averages 15%. What do you recommend?"

A: Analyze CloudWatch metrics for CPU, memory, and network. Consider:

  1. Downsize to m5.large (4x smaller, 4x cheaper)
  2. Use Compute Savings Plans for predictable workloads (up to 72% savings)
  3. Consider Graviton (m7g) for additional 20-40% cost reduction
  4. Implement auto-scaling to handle peaks

Lambda: Serverless Compute

Key Characteristics

  • Max duration: 15 minutes
  • Memory: 128 MB to 10,240 MB
  • Concurrency: 1,000 default (can increase)
  • Cold start: 100ms-1s (varies by runtime)

When to Use Lambda

Good Fit:

  • Event-driven processing (S3 triggers, API Gateway)
  • Short-running tasks (< 15 min)
  • Variable/unpredictable traffic
  • Microservice APIs with low latency requirements

Poor Fit:

  • Long-running processes (use Step Functions or ECS)
  • High-frequency, consistent load (EC2 cheaper at scale)
  • GPU-intensive workloads

Interview Question: Lambda vs EC2 Cost

Q: "Your API receives 10M requests/month, each taking 200ms and using 512MB. Should you use Lambda or EC2?"

A: Calculate Lambda cost:

  • Requests: 10M × $0.20/1M = $2.00
  • Compute: 10M × 0.2s × 0.5GB × $0.0000166667 = $16.67
  • Total: ~$19/month

EC2 t3.medium could handle this but requires management overhead. Lambda wins for simplicity at this scale. Beyond ~50M requests/month, EC2 becomes more cost-effective.

ECS: Container Orchestration

Launch Types

Type Use Case Pricing
EC2 Control over infrastructure Pay for EC2 instances
Fargate Serverless containers Pay per vCPU/memory-hour

ECS Architecture Components

  • Cluster: Logical grouping of services
  • Service: Maintains desired task count
  • Task Definition: Container configuration (like Dockerfile + docker-compose)
  • Task: Running container instance

Interview Question: ECS vs EKS

Q: "When would you choose ECS over EKS?"

A: Choose ECS when:

  • AWS-native integration is priority
  • Team lacks Kubernetes expertise
  • Simpler deployment model is acceptable
  • Vendor lock-in is not a concern

Choose EKS when:

  • Kubernetes expertise exists on team
  • Multi-cloud portability needed
  • Rich Kubernetes ecosystem required
  • Complex networking (service mesh) needed

EKS: Managed Kubernetes

EKS Pricing

  • Control plane: $0.10/hour (~$73/month)
  • Worker nodes: EC2/Fargate pricing
  • No additional charge for managed add-ons

Interview Question: EKS Node Types

Q: "What are the trade-offs between managed node groups, self-managed nodes, and Fargate for EKS?"

Option Pros Cons
Managed Node Groups AWS handles updates, easy scaling Less customization
Self-Managed Nodes Full control, custom AMIs You manage updates
Fargate Serverless, no nodes to manage Higher cost per vCPU, limited features

Compute Decision Framework

Need GPU? → P/G instance types
Need serverless?
  └── Short-lived (< 15min)? → Lambda
  └── Longer? → Fargate or Step Functions
Need containers?
  └── Kubernetes required? → EKS
  └── Simpler model? → ECS
Default → EC2 with Auto Scaling

Interview Tip: Always discuss cost implications, scaling behavior, and operational overhead when comparing compute options.

Next, we'll explore AWS storage services and selection criteria. :::

Quiz

Module 2: AWS Architecture & Services Deep Dive

Take Quiz