Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to locate CloudFront in front of ALB regardless of content type a user access?

I want to build a web/application server in AWS and I want to use CloudFront to deliver content with low latency and Application Load Balancer (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 of the following two alternatives is recommended?

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

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

Which one is the better pattern?

like image 859
SangminKim Avatar asked May 01 '19 00:05

SangminKim


People also ask

Should I put CloudFront in front of Alb?

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 ...

How do I use CloudFront with ALB?

To make a Cloudfront Distribution the only source of truth for an ALB is quite simple. The Cloudfront Distribution must send a custom header to the origin (the ALB) and the ALB should forward the requests, only if the custom header is present in the request with the appropriate value, much like an API Token (step_2).

How can I improve my CloudFront performance?

You can improve performance by increasing the proportion of your viewer requests that are served directly from the CloudFront cache instead of going to your origin servers for content. This is known as improving the cache hit ratio.

Can CloudFront connect to internal alb?

CloudFront only works with Internet-accessible resources.


1 Answers

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.

like image 101
Michael - sqlbot Avatar answered Sep 20 '22 10:09

Michael - sqlbot