Part 3: High-Performing Architectures

FCJ Workshops for Performance: This section aligns with EC2 Workshop (000004) for compute optimization and VPC Workshop (000003) for network performance concepts.

This section covers the performance pillar of the AWS Well-Architected Framework, ensuring efficient use of computing resources to meet system requirements.

Performance Efficiency Principles

Performance Efficiency is the ability to use computing resources efficiently to meet system requirements and maintain efficiency as demand changes and technologies evolve.

Key Focus Areas:

  1. Compute: Right instance types, serverless, containers
  2. Storage: Appropriate storage services and configurations
  3. Database: Right database type and features
  4. Network: Reduce latency, increase throughput

Content

This comprehensive section covers all aspects of designing high-performing architectures for the FCJ Midterm:

  • Serverless Compute (Lambda limits: 15min max, Fargate task specs)
  • Storage Performance (S3, EBS, EFS optimization)
  • Content Delivery and Caching (CloudFront, ElastiCache)
  • Monitoring and Optimization (CloudWatch, Auto Scaling)

AWS Fargate - Serverless Containers

AWS Fargate is a serverless compute engine for containers that removes the need to manage EC2 instances.

Fargate Architecture

ECS/EKS Cluster
├── Fargate Task 1 (0.5 vCPU, 1 GB RAM)
│   ├── Container 1: Web App
│   └── Container 2: Sidecar (logging)
├── Fargate Task 2 (1 vCPU, 2 GB RAM)
│   └── Container: API Service
└── Fargate Task 3 (4 vCPU, 8 GB RAM)
    └── Container: Batch Processing

Fargate Task Specifications (Memorize)

CPU Options (vCPU):

  • 0.25, 0.5, 1, 2, 4, 8, 16 vCPU

Memory (varies by CPU):

  • 0.25 vCPU: 0.5 GB, 1 GB, 2 GB
  • 0.5 vCPU: 1 GB - 4 GB (1 GB increments)
  • 1 vCPU: 2 GB - 8 GB (1 GB increments)
  • 2 vCPU: 4 GB - 16 GB (1 GB increments)
  • 4 vCPU: 8 GB - 30 GB (1 GB increments)
  • 8 vCPU: 16 GB - 60 GB (4 GB increments)
  • 16 vCPU: 32 GB - 120 GB (8 GB increments)

Fargate Key Features

Networking:

  • Each task gets its own Elastic Network Interface (ENI)
  • VPC integration with security groups
  • Public or private IP addresses
  • AwsVpc network mode (required)

Storage:

  • Ephemeral storage: 20 GB default (configurable up to 200 GB)
  • Default 20 GB is FREE (no additional cost)
  • Data lost when task stops
  • Use EFS for persistent storage

Performance:

  • Cold start: 35 seconds to 2 minutes (for new tasks)
  • Execution time: No hard limit (runs until task completes)
  • Compare: Lambda has 15-minute maximum execution timeout

Pricing (US East):

  • vCPU: $0.04048 per vCPU per hour
  • Memory: $0.004445 per GB per hour
  • Example: 1 vCPU + 2 GB = $0.04048 + ($0.004445 × 2) = $0.04937/hour

Fargate vs EC2 Launch Types

AspectFargateEC2
ManagementServerless, AWS managesYou manage EC2 instances
PricingPay per task (vCPU + memory)Pay for EC2 instances
ScalingAutomatic, instantManual or Auto Scaling Groups
CostHigher per taskLower if fully utilized
Best ForVariable workloads, simplicityPredictable, high utilization

Fargate vs Lambda - Complete Comparison

FeatureAWS FargateAWS Lambda
Execution TimeNo hard limit15 minutes maximum
MemoryUp to 120 GBUp to 10 GB
CPUUp to 16 vCPUUp to 6 vCPU
Cold Start35s - 2 minutes100ms - 2 seconds
Warm StartN/A (always running)~10ms
Default Storage20 GB (FREE)10 GB /tmp
NetworkingFull VPC, ENI per taskVPC optional
Container SupportFull Docker supportContainer images (10 GB max)
Pricing ModelPer second (vCPU + memory)Per request + GB-second
Best ForLong-running containersEvent-driven, short tasks
Use CaseMicroservices, APIsServerless functions

When to Use Fargate

Use Fargate When:

  • Microservices architectures
  • Batch processing jobs
  • Variable or unpredictable workloads
  • Want to eliminate server management
  • Quick deployments without infrastructure setup

Don’t Use Fargate When:

  • Need Windows containers (limited support)
  • Require GPU workloads (use EC2 with GPU instances)
  • Very high utilization (EC2 more cost-effective)

AWS Lambda - Event-Driven Architecture

AWS Lambda runs code without provisioning servers, automatically scaling based on demand.

Lambda Event-Driven Architecture

Event Sources              Lambda Functions         Destinations
┌─────────────┐           ┌──────────────┐        ┌──────────────┐
│ API Gateway │──────────>│ Process HTTP │───────>│     RDS      │
└─────────────┘           └──────────────┘        └──────────────┘

┌─────────────┐           ┌──────────────┐        ┌──────────────┐
│ S3 Events   │──────────>│ Image Resize │───────>│      S3      │
└─────────────┘           └──────────────┘        └──────────────┘

┌─────────────┐           ┌──────────────┐        ┌──────────────┐
│ DynamoDB    │──────────>│ Stream Proc  │───────>│     SNS      │
│ Streams     │           └──────────────┘        └──────────────┘
└─────────────┘

┌─────────────┐           ┌──────────────┐        ┌──────────────┐
│ SQS Queue   │──────────>│ Process Msgs │───────>│  DynamoDB    │
└─────────────┘           └──────────────┘        └──────────────┘

┌─────────────┐           ┌──────────────┐        ┌──────────────┐
│ EventBridge │──────────>│ Scheduled    │───────>│ CloudWatch   │
│ (Cron)      │           │ Backups      │        │     Logs     │
└─────────────┘           └──────────────┘        └──────────────┘

Lambda Limits (FCJ Midterm Critical)

Hard Limits (cannot be changed):

  • Execution timeout: 15 minutes maximum
  • Deployment package: 50 MB (zipped), 250 MB (unzipped)
  • Environment variables: 4 KB total
  • /tmp storage: 10 GB (previously 512 MB)
  • Concurrent executions: 1000 per region (default, can request increase)

Configurable:

  • Memory: 128 MB to 10 GB (1 MB increments)
  • Ephemeral storage (/tmp): 512 MB to 10 GB
  • Note: CPU allocation scales with memory

Lambda Memory and Performance

Memory determines CPU allocation:

  • 128 MB memory → ~0.08 vCPU equivalent
  • 1,769 MB memory → 1 full vCPU
  • 10,240 MB (10 GB) → ~6 vCPUs

Lambda Power Tuning: Tool to find optimal memory/cost balance

Lambda Concurrency

Concurrency = Number of function instances running simultaneously

Types:

  1. Unreserved Concurrency: Default, shared pool (1000 per region)
  2. Reserved Concurrency: Dedicated capacity for specific function
  3. Provisioned Concurrency: Pre-initialized instances (warm start)

Cold Start vs Warm Start:

  • Cold Start: First invocation, initialize runtime (100ms to 2 seconds typical)
  • Warm Start: Reuse existing instance (~single digit ms)
  • Compare with Fargate: Fargate cold start is 35s-2min (much slower)

Reducing Cold Starts:

  • Use Provisioned Concurrency (cost: $0.015 per GB-hour)
  • Keep functions warm (scheduled pings)
  • Optimize package size
  • Use ARM64 (Graviton2) processors

Lambda Pricing (FCJ Midterm)

Free Tier (per month):

  • 1 million requests
  • 400,000 GB-seconds of compute time

Pricing (US East):

  • Requests: $0.20 per 1 million requests
  • Compute: $0.0000166667 per GB-second

Example Calculation:

  • 3 million requests/month
  • 512 MB memory, 200ms average execution
  • Compute: 3M × 0.2s × 0.5 GB = 300,000 GB-seconds
  • Cost: (3M - 1M) × $0.20/1M + (300K - 400K) × $0.0000166667 = $0.40 (requests only, compute free)

Lambda Use Cases

Perfect For:

  • Real-time file processing (S3 trigger)
  • Stream processing (Kinesis, DynamoDB Streams)
  • Web APIs (API Gateway + Lambda)
  • Backend for mobile apps
  • Scheduled tasks (cron jobs)
  • Event-driven workflows

Not Ideal For:

  • Long-running processes (>15 minutes)
  • High-frequency, predictable workloads (EC2 cheaper)
  • Stateful applications
  • Complex dependencies (large packages)

Auto Scaling with CloudWatch

Auto Scaling Architecture

┌─────────────────────────────────────────────────────────────┐
│                      CloudWatch                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Metrics:                                           │   │
│  │  • CPU Utilization: 85%  ←─ Threshold: 70%         │   │
│  │  • Request Count: 5000/min                          │   │
│  │  • Network In/Out                                   │   │
│  └───────────────────────┬─────────────────────────────┘   │
└────────────────────────────┼───────────────────────────────┘
                             │ Alarm Triggered!
┌─────────────────────────────────────────────────────────────┐
│              Auto Scaling Group                             │
│  Min: 2  │  Desired: 4  │  Max: 10                         │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Scaling Policy: Add 2 instances when CPU > 70%    │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐  │
│  │   EC2    │  │   EC2    │  │   EC2    │  │   EC2    │  │
│  │ Instance │  │ Instance │  │ Instance │  │ Instance │  │
│  │    #1    │  │    #2    │  │    #3    │  │    #4    │  │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘  │
│       ↑            ↑             ↑ NEW         ↑ NEW       │
└───────┼────────────┼─────────────┼─────────────┼───────────┘
        │            │             │             │
        └────────────┴─────────────┴─────────────┘
         ┌───────────▼────────────┐
         │  Application Load      │
         │     Balancer           │
         └────────────────────────┘

Launch Template Configuration

Launch Template defines instance configuration for Auto Scaling:

{
  "ImageId": "ami-0c55b159cbfafe1f0",
  "InstanceType": "t3.medium",
  "SecurityGroups": ["sg-0123456789abcdef0"],
  "IamInstanceProfile": {
    "Arn": "arn:aws:iam::123456789012:instance-profile/MyRole"
  },
  "UserData": "IyEvYmluL2Jhc2gKYXB0IHVwZGF0ZQo=",
  "TagSpecifications": [{
    "ResourceType": "instance",
    "Tags": [{"Key": "Name", "Value": "AutoScaled"}]
  }]
}

Components:

  • AMI ID, instance type
  • Security groups, IAM role
  • User data (startup script)
  • Network settings, storage

Scaling Policies Deep Dive

Example JSON:

{
  "TargetValue": 70.0,
  "PredefinedMetricType": "ASGAverageCPUUtilization",
  "ScaleInCooldown": 300,
  "ScaleOutCooldown": 60
}

How It Works:

  • AWS creates CloudWatch alarms automatically
  • Scales out when metric > target
  • Scales in when metric < target
  • You set target, AWS manages the rest

Step Scaling

Configuration:

  • Metric: CPU Utilization
  • Alarm 1: CPU > 80% → Add 2 instances
  • Alarm 2: CPU > 90% → Add 4 instances
  • Alarm 3: CPU < 30% → Remove 1 instance

Cooldown Period: 300 seconds (default) - prevent rapid scaling

Simple Scaling

Configuration:

  • CPU > 80% → Add 1 instance
  • Wait for cooldown period (300s)
  • Evaluate again

Limitation: One adjustment at a time

CloudWatch Metrics for Scaling

EC2 Default Metrics (5-minute, free):

  • CPUUtilization (%)
  • NetworkIn/Out (Bytes)
  • DiskReadOps/WriteOps (Count)
  • StatusCheckFailed

Detailed Monitoring (1-minute, $0.14/month per instance):

  • Same metrics, higher resolution
  • Faster response to load changes

Custom Metrics:

  • Application-level metrics
  • Queue depth (SQS)
  • Active users
  • Request processing time

Sending Custom Metrics:

aws cloudwatch put-metric-data \
  --namespace "MyApp" \
  --metric-name "ActiveUsers" \
  --value 150

Auto Scaling Best Practices

  1. Use Target Tracking for simple, predictable scaling
  2. Set appropriate cooldowns (prevent thrashing):
    • Scale out: 60 seconds (fast response)
    • Scale in: 300 seconds (avoid premature termination)
  3. Monitor multiple metrics (CPU, memory, request count)
  4. Test scaling policies under load
  5. Use ALB health checks for Auto Scaling
  6. Implement lifecycle hooks for graceful shutdown

Lifecycle Hooks

Lifecycle Hooks pause instance launch/termination for custom actions.

Use Cases:

  • Launch: Configure instance, register with service
  • Terminate: Drain connections, backup data

Hook Types:

  • EC2_INSTANCE_LAUNCHING: Before instance goes into service
  • EC2_INSTANCE_TERMINATING: Before instance terminates

Timeout: Default 1 hour (configurable)

CloudWatch Monitoring Architecture

CloudWatch Components

┌────────────────────────────────────────────────────────────┐
│                    Data Sources                            │
├────────────────────────────────────────────────────────────┤
│ EC2: CPU, Network, Disk                                    │
│ Lambda: Invocations, Duration, Errors                      │
│ RDS: Connections, CPU, IOPS                                │
│ ELB: Request Count, Latency, Errors                        │
│ Application Logs → CloudWatch Logs                         │
│ VPC Flow Logs → Network traffic analysis                   │
└──────────────────────────┬─────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐
│                   CloudWatch                               │
├────────────────────────────────────────────────────────────┤
│ Metrics → Alarms → Actions                                 │
│   ↓         ↓        ↓                                      │
│ Storage  Threshold  SNS, Auto Scaling, Lambda              │
└──────────────────────────┬─────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐
│                  Outputs & Actions                         │
├────────────────────────────────────────────────────────────┤
│ • Dashboards (visualize metrics)                           │
│ • Alarms (trigger actions)                                 │
│ • Logs Insights (query logs)                               │
│ • EventBridge (event-driven automation)                    │
│ • S3 Export (long-term archival)                           │
└────────────────────────────────────────────────────────────┘

CloudWatch Metrics

Standard Metrics (5-minute intervals, free):

  • AWS services automatically send metrics
  • CPU, network, disk for EC2
  • Request count, latency for ALB

Detailed Monitoring (1-minute intervals, paid):

  • EC2: $0.14/instance/month
  • ALB: $0.10/ALB/month
  • Faster detection of issues

Custom Metrics:

  • Send application-specific metrics
  • API: PutMetricData
  • Resolution: 1-minute or 1-second (high-resolution)
  • Pricing: $0.30 per metric per month

CloudWatch Logs

Log Groups: Container for log streams (e.g., /aws/lambda/my-function)

Log Streams: Sequence of log events from same source (e.g., instance ID)

Features:

  • Retention: 1 day to 10 years (or never expire)
  • Insights: SQL-like query language for log analysis
  • Metric Filters: Extract metrics from logs
  • Subscriptions: Stream logs to Kinesis, Lambda, S3

Logs Insights Query Example:

fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

CloudWatch Alarms

Alarm States:

  • OK: Metric within threshold
  • ALARM: Metric breached threshold
  • INSUFFICIENT_DATA: Not enough data

Alarm Actions:

  • Send SNS notification (email, SMS, Lambda)
  • Execute Auto Scaling policy
  • Stop/terminate/reboot EC2 instance
  • Trigger Systems Manager automation

Composite Alarms: Combine multiple alarms (AND, OR)

CloudWatch Dashboards

Purpose: Visualize metrics in custom dashboards

Widget Types:

  • Line graphs, stacked area charts
  • Number widgets (single metric value)
  • Query-based widgets (Logs Insights)
  • Text widgets (markdown notes)

Sharing: Share dashboards publicly or within organization

Pricing: First 3 dashboards free, $3/month per dashboard after

CloudWatch vs CloudTrail vs Config

ServicePurposeWhat It Monitors
CloudWatchPerformance monitoringMetrics, logs, alarms
CloudTrailAuditing API callsWho did what, when
ConfigConfiguration complianceResource configs over time

Use Together: CloudWatch (performance) + CloudTrail (security) + Config (compliance)

FCJ Midterm Preparation Tips for High-Performing Architectures

  1. Fargate eliminates EC2 management, pay per task
  2. Lambda maximum execution time is 15 minutes
  3. Lambda memory determines CPU allocation (1,769 MB = 1 vCPU)
  4. Target tracking is recommended Auto Scaling policy
  5. Cooldown periods: Scale out fast (60s), scale in slow (300s)
  6. CloudWatch detailed monitoring: 1-minute resolution (paid)
  7. Custom metrics: $0.30 per metric per month
  8. Fargate ephemeral storage: Up to 200 GB (lost on stop)