18.17 Load balancer in a three-tier architecture
Why the tiers are separate
Presentation, application, and data are separated so a sale spike can add web instances without putting the database on the internet. Amazon, Flipkart, and IRCTC on a busy day are the traffic picture only. This is not their internal design. The database stays in a private subnet. Users never open it. The web tier can grow from 2 instances to 6 without a new database.
What the picture contains
Users → internet-facing ALB → web ASG (min 2 max 6) → internal ALB → app ASG (min 2 max 4) → RDS Multi-AZ with no balancer in front.
Users on the internet
|
v
Internet-facing ALB
public subnets, two AZs
|
v
Web tier
EC2 Auto Scaling group
min 2, desired 2, max 6
target group TG-web, port 80
|
v
Internal ALB
private subnets, two AZs
|
v
App tier
EC2 Auto Scaling group
min 2, desired 2, max 4
target group TG-api, port 8080
|
v
Data tier
Amazon RDS MySQL, Multi-AZ
private subnets, port 3306
no load balancer in front
There is no load balancer in front of the primary database. You do not round-robin writes to two primaries. A read replica is optional and is not fronted by either of these Application Load Balancers. This lesson does not build a reader endpoint.
The tiers, with the numbers we set:
- Users on the internet.
- Internet-facing Application Load Balancer in two public subnets and two Availability Zones.
- Web tier: Auto Scaling group, minimum 2, desired 2, maximum 6, target group
TG-web, port 80, behind the public balancer. - Internal Application Load Balancer in two private subnets and two Availability Zones.
- App tier: Auto Scaling group, minimum 2, desired 2, maximum 4, target group
TG-api, port 8080, behind the internal balancer. - Data tier: Amazon RDS MySQL, Multi-AZ, private subnets, port 3306 allowed only from the app tier security group.
Both of those balancers are Application Load Balancers, so cross-zone load balancing is already on. Section 18.18 does not ask you to toggle it here.
How the security groups chain
One line each. The source is the previous tier's security group, not the whole internet.
- Public balancer security group: inbound 443 from
0.0.0.0/0. - Web security group: inbound 80 from the public balancer security group only.
- Internal balancer security group: inbound 8080 from the web security group only.
- App security group: inbound 8080 from the internal balancer security group only.
- RDS security group: inbound 3306 from the app security group only.
If you kept the HTTP port 80 redirect from section 18.14, the public balancer security group also allows 80 from 0.0.0.0/0. That extra line is only for the redirect. It does not open the web instances to the world.
How one product page and one checkout call move
A product-page request goes through web, internal ALB, app, and RDS for a read. Checkout uses TG-checkout then the same internal path to write the RDS primary.
One request walks down the tiers: browser, public ALB, web, internal ALB, app, then RDS.
Flipkart-style traffic, our numbers, not a real shop's design.
Product page:
- The browser asks for
https://www.example.com/product/42. - The internet-facing balancer accepts it on 443.
- The rule sends it to
TG-web. - One of the 2 web instances, desired capacity 2, builds the page.
- That web instance calls the internal balancer on port 8080.
- The internal balancer sends the call to one of the 2 app instances in
TG-api. - The app instance reads the product row from RDS on port 3306.
- The row comes back app, internal balancer, web, public balancer, browser.
- RDS was never the next hop of the public balancer.
Checkout:
- The browser posts
https://www.example.com/checkout. - The internet-facing balancer accepts it on 443.
- The rule sends it to the checkout target group from section 18.13, desired 2, not to the browsing group.
- That checkout instance calls the same internal balancer on port 8080.
- The internal balancer sends it to
TG-api. - The app instance writes the order to the RDS primary on port 3306.
- The write is one primary, not a round robin across two databases.
- You should see two balancers in the path, and no balancer between the app instance and RDS.
What is not in this picture
Do not register the RDS instance in TG-web or TG-api. Do not put the database behind the same Application Load Balancer as the web servers. The balancer speaks HTTP to web and app instances. The database speaks MySQL on 3306 to the app tier only.
Three tiers: the outer door, the service inside, and the data. There is no load balancer in front of the database. The guest does not walk into the store room.
तीन थर: बाहेरचा दरवाजा, आतली सेवा, आणि डेटा. डेटाबेससमोर लोड बॅलन्सर नाही. पाहुणा स्टोअर रूममध्ये जात नाही.
तीन परत: बाहर का दरवाज़ा, अंदर की सेवा, और डेटा. डेटाबेस के सामने लोड बैलेंसर नहीं. मेहमान स्टोर रूम में नहीं जाता.