Architecture
Fast Autoscaler follows a modular architecture design that separates concerns and enables extensibility.
High-Level Components
The Fast Autoscaler consists of these main components:
- Lambda Function (Entry Point): Triggered on a schedule, coordinates the scaling process
- Queue Metrics Provider: Abstraction for retrieving message counts from different queue providers
- Scaling Logic: Core algorithm that determines the appropriate scaling action
- State Management: Tracks scaling events and manages cooldown periods
- AWS Integration: Lightweight wrapper around AWS services
Component Interactions
- The Lambda function is triggered by CloudWatch Events (typically every minute)
- Queue metrics are retrieved from the configured provider (e.g., SQS)
- Current ECS service state is retrieved (current task count)
- Scaling logic determines if adjustment is needed based on metrics and configuration
- If scaling is required and not in cooldown, the ECS service is updated
- Scaling state is stored in S3 for future reference and cooldown management
Directory Structure
autoscaler/
├── __init__.py
├── main.py # Lambda handler and entry point
├── scaler.py # Core scaling logic
├── queue_metrics/ # Queue metrics providers
│ ├── __init__.py
│ ├── sqs.py # SQS implementation
│ └── amq.py # Future AMQ support
├── state/ # State management
│ ├── __init__.py
│ └── s3_state.py # S3-based state tracking
└── aws/ # AWS integration
├── __init__.py
└── wrapper.py # AWS service wrapper
Extensibility
This architecture makes it easy to:
- Add support for new queue providers (just add a new implementation in the queue_metrics package)
- Modify scaling logic independently of metrics collection
- Change state storage mechanisms if needed
- Support different AWS resource types for scaling (beyond ECS)