I wonder how well this works for content that is truly dynamic. Seems like it would necessarily be slower for those pages that change on every request.
I wonder how well this works for content that is truly dynamic. Seems like it would necessarily be slower for those pages that change on every request.
Simplified example (ignoring DNS latency, assuming symmetric paths):
User to CloudFront RTT is 30ms
User to Origin RTT is 100ms
CloudFront to Origin RTT is 100ms
It seems clear that User to Origin is faster than User to CloudFront to Origin, but not if you consider TCP mechanics.
If the User makes an HTTP request for a 4KB file to the Origin directly, it will take 100ms to set up the connection, 50ms for the request to reach the Origin, and another 50ms for the first response byte to arrive. Total: 200ms. If the origin does not have a big initial congestion window, it will take another 100ms for the last byte to arrive. Total: 300ms.
If the User makes an HTTP request for a 4KB file through CloudFront, it will take 30ms to set up the TCP connection. The request packet(s) will take 15ms to reach CloudFront. CloudFront tries to maintain a persistent TCP connection to the Origin, which avoids set-up time and slow start. The request to the Origin will take 100ms to complete, and another 15ms to reach the User. Total: 160ms.
Using CloudFront as an intermediary could reduce latency by a lot, even if no caching is going on.
Also, CloudFlare offers the same service, but with added security and anti-spam features.