2.1 Design Scalable and Loosely Coupled Architectures
1. Scalability
Scalability is the ability of a system to handle increased demand by adding resources. This is done by adding more instances (horizontal scaling) or upgrading existing ones (vertical scaling).
Source: StormIT
Aspect | Vertical Scaling | Horizontal Scaling |
---|---|---|
Definition | Increases the capacity of a single server by upgrading hardware. | Adds more servers or instances to distribute the workload. |
Performance | Improves performance by making a single instance more powerful. | Balances workload across multiple instances. |
Flexibility | Limited by the physical limits of the hardware. | Virtually unlimited by adding more instances. |
Implementation | Easy to implement (e.g., changing instance type in AWS). | More complex, requiring load balancers and distributed systems. |
Cost Efficiency | More cost-efficient for smaller workloads. | Better for handling large-scale or unpredictable workloads. |
Fault Tolerance | Less fault-tolerant; failure affects the entire system. | High fault tolerance; failure of one instance doesn’t impact others. |
2. Loosely Coupled Architectures
Loosely coupled architectures ensure that application components are independent and communicate via interfaces. This design improves fault tolerance, scalability, and maintainability.
Amazon SQS (Simple Queue Service):
Source: ömer faruk gülerden
- Enables asynchronous communication between components.
- Example: Queueing customer orders for processing without overwhelming the system.
Amazon SNS (Simple Notification Service):
- Pushes notifications to multiple subscribers in real-time.
- Example: Sending order status updates via email or SMS.
3. Stateless vs. Stateful Architectures
Aspect | Stateless Applications | Stateful Applications |
---|---|---|
Definition | Do not retain user data between sessions. | Retain session data between requests. |
Scalability | Easier to scale due to no dependency on user session data. | More complex to scale as session state must be managed. |
Data Persistence | No persistence; processes each request independently. | Requires external storage for persisting state. |
Example | REST APIs, where each request is treated separately. | Chat apps where messages and user sessions persist. |
State Management | Not required. | Uses services like DynamoDB or RDS to manage state. |
4. Event-Driven Architectures
Event-driven architectures trigger actions in response to events. This approach improves responsiveness and reduces latency in workflows.
Amazon EventBridge:
- Automatically triggers workflows based on events like resource updates or application activity.
- Example: Scaling an EC2 instance when CPU usage exceeds a threshold.
- Benefits:
- Handles real-time events efficiently.
- Improves application responsiveness.
5. Multi-Tier Architectures
Multi-tier architectures divide applications into layers (e.g., presentation, logic, and database). This separation improves modularity, fault tolerance, and scalability.
Layers in a Multi-Tier Architecture:
- Presentation Layer: User interfaces (e.g., websites on S3 or CloudFront).
- Application Layer: Business logic (e.g., hosted on Lambda or EC2).
- Database Layer: Data storage (e.g., RDS or DynamoDB).
Source: Particular Software
6. Load Balancing
Load balancing distributes incoming traffic across multiple servers to improve performance and ensure high availability.
Source: Cloudiofy
Application Load Balancer (ALB):
- Routes HTTP/HTTPS traffic with advanced features.
- Example: Routing traffic to different EC2 instances based on URL paths.
Network Load Balancer (NLB):
- Handles high-performance traffic with ultra-low latency.
7. Caching
Caching stores frequently accessed data closer to the user to reduce latency and improve performance.
Amazon ElastiCache:
- In-memory caching (supports Redis and Memcached).
- Example: Caching database query results to speed up responses.
Amazon CloudFront:
- A content delivery network (CDN) that caches static content at edge locations.
- Example: Delivering website images faster worldwide.
8. Serverless Architectures
Serverless architectures automatically manage infrastructure, allowing you to focus on writing code. They scale automatically and charge only for execution time.
Source: Kerno
This diagram illustrates a serverless architecture where users interact with an application through a REST API managed by API Gateway.
- AWS Cognito handles user authentication.
- Requests are sent to AWS Lambda, which processes them using application logic.
- Data is stored in DynamoDB, while static files (e.g., images) are stored in S3.
AWS Lambda:
- Runs code in response to events without provisioning servers.
- Example: Processing files uploaded to an S3 bucket.
- Benefits:
- Scales automatically based on demand.
- Cost-efficient for infrequent workloads.
9. Containers
Containers package applications with their dependencies, ensuring they run consistently across different environments.
AWS Services for Containers:
- Amazon ECS: Fully managed container orchestration service.
- Amazon EKS: Kubernetes-based container management.
10. Orchestrating Workflows
Orchestrating workflows ensures that processes execute in the right order for smooth operations and automation.
AWS Step Functions:
- Coordinates workflows between AWS services.
- Example: Automating an e-commerce order process, from payment to shipment.