I want to build a web/application server in AWS and I want to use CloudFront to deliver content with low latency and ALB to balance traffic between servers.

If there are some contents needed to be cached, using CloudFront in front of ALB should benefit.

However, If not, is it still recommended to use CloudFront in front of ALB in view of performance and cost?

For example, Which one is recommended between them below.

  1. User always accesses ALB through CloudFront regardless of content the user access.

  2. User access CloudFront or ALB directly depending on the content the user access.

Which one is a better pattern?

1 Answers

Michael - sqlbot On Best Solutions

Neither option is wrong, but using CloudFront in front of ALB does provide some advantanges even for non-cacheable, dynamic content -- including faster TLS negotiation for viewers who are more distant from the ALB and optimized routing of requests, globally on the AWS Edge Network, from an edge location near the viewer, to the region where the ALB is located.

Depending on the location of the ALB and location of the viewer, CloudFront bandwidth out to the Internet can be up to $0.005/GB cheaper, compared to the ALB/EC2 pricing, or can be more... but the bandwidth from ALB to CloudFront is free, so you don't pay both charges.