Multi-tier architecture patterns in AWS - Time & Space Complexity
When building multi-tier architectures in the cloud, it's important to understand how the time to process requests grows as more users or data are involved.
We want to know how the system's work changes when the number of requests or components increases.
Analyze the time complexity of handling requests through a typical 3-tier AWS architecture.
// Simplified AWS multi-tier setup
// 1. Client sends request to Application Load Balancer (ALB)
// 2. ALB forwards request to EC2 instances in Auto Scaling Group (App tier)
// 3. EC2 instances query RDS database (Data tier)
// 4. RDS returns data to EC2 instances
// 5. EC2 instances respond back through ALB to client
This sequence shows how a request flows through the tiers to get processed and responded to.
Look at what happens repeatedly as requests increase.
- Primary operation: Each incoming request triggers API calls to the ALB, EC2 instances, and RDS database.
- How many times: Once per request, repeated for every user request.
As the number of requests (n) grows, each request goes through the same steps.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 ALB + 10 EC2 + 10 RDS calls |
| 100 | About 100 ALB + 100 EC2 + 100 RDS calls |
| 1000 | About 1000 ALB + 1000 EC2 + 1000 RDS calls |
Pattern observation: The total operations grow directly with the number of requests.
Time Complexity: O(n)
This means the work grows linearly with the number of requests; doubling requests roughly doubles the work.
[X] Wrong: "Adding more tiers will multiply the time complexity exponentially."
[OK] Correct: Each tier adds fixed steps per request, so the total work grows linearly, not exponentially.
Understanding how multi-tier systems scale with requests helps you design and explain cloud architectures clearly and confidently.
"What if we added caching between the app and data tiers? How would the time complexity change?"
Practice
Solution
Step 1: Understand multi-tier architecture concept
Multi-tier architecture divides an app into layers such as web, application, and database tiers.Step 2: Identify benefits of layering
This separation improves security by isolating layers and helps scale parts independently.Final Answer:
To separate an application into layers for better security and scalability -> Option CQuick Check:
Multi-tier = layers for security and scaling [OK]
- Thinking all parts should be on one server
- Assuming all components need internet access
- Confusing multi-tier with single-tier or monolithic
Solution
Step 1: Recall subnet types in AWS
Public subnets have a route to the internet gateway, allowing internet access.Step 2: Match subnet to web servers
Internet-facing web servers need public subnets to receive traffic from users.Final Answer:
Public subnet -> Option AQuick Check:
Internet-facing = public subnet [OK]
- Choosing private subnet which blocks internet access
- Confusing isolated subnet with public
- Thinking VPN subnet is for public web servers
Solution
Step 1: Identify tiers and their security needs
The database tier holds sensitive data and needs strong protection.Step 2: Determine subnet placement
Private subnets restrict internet access, ideal for databases to prevent direct exposure.Final Answer:
Database tier -> Option AQuick Check:
Database = private subnet for security [OK]
- Placing web tier in private subnet
- Assuming load balancer is in private subnet
- Confusing application tier with database tier
Solution
Step 1: Analyze connectivity between application and database tiers
Application tier must be allowed by database security group to connect on required ports.Step 2: Check common misconfigurations
If security group blocks inbound traffic, connection fails despite correct subnet placement.Final Answer:
The database security group does not allow inbound traffic from the application tier -> Option DQuick Check:
Security group rules control traffic between tiers [OK]
- Blaming web tier subnet for app-db connection
- Assuming public IP needed for private subnet
- Ignoring security group inbound rules
Solution
Step 1: Assign subnet types based on tier roles
Web tier needs public subnet for user access; app and database tiers should be private for security.Step 2: Provide outbound internet for private tiers
Use NAT gateway so private tiers can access internet for updates without exposing them inbound.Final Answer:
Place web servers in public subnet with internet gateway; app and database servers in private subnets with NAT gateway for outbound internet -> Option BQuick Check:
Public web, private app/db, NAT for outbound [OK]
- Putting database in public subnet
- Giving private tiers direct internet access
- Mixing subnet roles incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
