← Solutions Architect Associate study path

Performance and cost · 11 min

Network performance and cost on AWS

In this lesson you will learn when to use Amazon CloudFront or AWS Global Accelerator to bring an application closer to its users, where data transfer is charged on AWS and how a gateway endpoint lowers what a NAT gateway charges.

The network is the path data travels between users, servers and AWS services. Networking enters the SAA-C03 exam through two tasks in the exam guide: task 3.4 asks for high-performing network architectures and task 4.4 for cost-optimized network architectures. Both tasks depend on the same thing, which is the path each travels. If a byte travels far, the application responds slowly, and if it leaves an , a Region or goes to the internet, it shows up on the bill. For example, an online store with servers in the United States and customers in Chile pays in time, because each photo travels far, and pays in money, because each photo goes out to the internet.

Bringing the application closer to users

An application in us-east-2 (Ohio), an AWS Region in the United States, responds more slowly to a user in Santiago than to one in Ohio, because each request crosses the internet there and back. Amazon CloudFront and AWS Global Accelerator shorten that path with the AWS global network, which has entry points in many cities called edge locations, but they do it in different ways. For example, the customer in Santiago enters the AWS network at a nearby point and from there their data travels over AWS cables instead of over the internet.

Top, CloudFront responds from the edge location with its cache and only goes to the origin if it doesn't have the object. Bottom, Global Accelerator gives two static IP addresses and carries TCP and UDP traffic over the AWS network to the nearest healthy endpoint group

CloudFront keeps copies of the content in the edge locations, in a , and only goes to the origin, which is where the original lives (an S3 bucket, an ALB or another web server), when the edge doesn't have the object. Global Accelerator, on the other hand, has no cache: it receives the traffic at the edge with two static IP addresses and carries it over the AWS network to the nearest healthy endpoint, which is the server that responds. That endpoint can be an NLB, an ALB, an EC2 instance or an Elastic IP address.

Because of that difference, each service is chosen by the type of traffic:

  • Amazon CloudFront, which is for web content over and HTTPS, static or dynamic. Static content is the same for everyone, like a photo, and dynamic content changes on each visit, like each customer's cart.
  • AWS Global Accelerator, which is for TCP or traffic that isn't web, such as online games and voice over IP, which is calling over the internet, or for clients that need static IP addresses.

Besides caching, CloudFront terminates close to the user, that is, it sets up the secure connection there, and keeps connections open with the origin. That is why it also speeds up whose responses can't be cached. In Global Accelerator, on the other hand, what matters are the two IP addresses, which stay the same as long as the accelerator exists even if you change the endpoints behind it. For example, the store puts CloudFront in front of its product photos, while an online game that uses UDP puts Global Accelerator in front of its servers.

CloudFront or Global Accelerator?

0 of 4

Tap the service that fits each case.

  1. Images and videos from a news site for readers across Latin America

  2. A multiplayer game over UDP with servers in two Regions

  3. IoT devices with hardcoded IP addresses that can't be updated

  4. A static website stored in an Amazon S3 bucket

Where is data transfer charged?

Map of charges in us-east-2: free within a zone with a private IP address and from EC2 to S3 in the same Region; 0.01 USD per GB in each direction between zones; the NAT gateway charges per hour and per GB; outbound to the internet, to another Region and over Direct Connect is charged

Data transfer is moving data from one place to another, and AWS charges for it based on the path each byte follows. The prices are examples from us-east-2 and change by Region, but the rules are the same in all of them:

  • Between instances in the same zone with , where transfer isn't charged.
  • Between zones in the same Region, where EC2, RDS, ElastiCache and network interfaces pay 0.01 USD per GB in each direction.
  • From EC2 to S3 in the same Region, where transfer isn't charged.
  • Out to the internet, where it is charged per GB, with 100 GB free per month across all services and Regions.
  • From an origin in AWS to CloudFront, where you don't pay for transfer and only pay for what CloudFront delivers to users.

For example, when the store's server saves a photo to S3 in the same Region it doesn't pay for transfer, but when a customer downloads that photo from the internet it is charged.

The charge between zones is the price of availability. A Multi-AZ architecture, which spreads its servers across several zones, pays that 0.01 USD per GB in exchange for continuing to work if a zone goes down. For example, if the store's database is in one zone and its web servers in another, the data for each query pays that charge between zones.

The NAT gateway and gateway endpoints

Inside AWS, your servers live in a VPC, which is your private network, split into subnets. A NAT gateway lets the instances in a reach the internet without accepting connections that come from outside. It charges for each hour it exists, where a partial hour counts as a full one, and for each GB it processes, wherever it goes. The AWS example in us-east-2 is 0.045 USD per hour and 0.045 USD per GB. For example, a private server of the store uses the NAT gateway to download updates from the internet, and nobody from outside can get into it that way.

This per-GB charge shows up even if the destination is free. When private instances send data to S3 through the NAT gateway, the transfer from EC2 to S3 in the same Region isn't charged, but each GB pays the NAT processing. A VPC gateway endpoint for S3 (or for DynamoDB), on the other hand, is a direct entrance from your VPC to that service: it sends that traffic over the AWS network without going through the NAT, and it doesn't charge per hour or for data. For example, if the store's private servers save their backups to S3 every night, a gateway endpoint removes the NAT charge for each GB of those backups.

Turn the internet gateway and the NAT gateway on and off

A VPC with a public subnet and a private one. The public one holds the web server and the NAT gateway; the private one, an instance that needs to download patches. Turn the two doors to the internet on and off.

Internet gateway
NAT gateway
  • From the internet to the web serverPublic subnetAllowed
  • From the private instance to the internetTo download patchesAllowed
  • From the internet to the private instanceA connection that starts outsideBlocked
  • Between the two subnetsLocal routeAllowed

What happened?

The public subnet has its 0.0.0.0/0 route to the internet gateway, so the web server gets visits. The private subnet goes out through the NAT gateway, which sits in the public subnet, and nobody outside can open a connection to it.

One NAT gateway per zone or a shared one

Three ways to place the NAT gateway: one in each zone, one shared across zones and a regional one, with what each one charges

Where you put the NAT gateway also changes the bill. If the NAT gateway is in a different zone from the instance, you also pay for transfer between zones. That is why you have three options, each with its own cost:

  • One NAT gateway in each zone, where you pay for more hours.
  • A shared NAT gateway, where you pay for transfer between zones and, if its zone goes down, the instances in the other zones are left without internet access.
  • A regional NAT gateway, which charges one hour for each zone it operates in.

For example, if the store has servers in two zones and puts a single NAT gateway in the first one, the servers in the second pay for transfer between zones and are left without internet if the first zone fails.

How do you lower the bill?

Instances in private subnets copy 20 TB per month to an S3 bucket in the same Region, and almost the entire network bill is NAT gateway processing. What do you change?

If your account uses the new experience

In a new experience account, VPC, NAT gateway, gateway endpoints and CloudFront are available, although CloudFront works without Lambda@Edge. AWS Global Accelerator isn't available, and this account doesn't support cross-Region features either, so you study the scenarios with endpoints in two Regions in theory or try them in a full account. For example, you can create a CloudFront distribution for a practice bucket, but not a Global Accelerator accelerator.

cloud path tip: a NAT gateway charges from the moment you create it, so delete it when you finish each practice session.

On the exam

The questions on this topic describe the traffic and where it goes. These words in the question point to the answer:

  • "Static content", "cache" or "users around the world" with HTTP, which point to CloudFront.
  • "UDP", "static IP addresses", "games", "VoIP" or endpoints in several Regions, which point to Global Accelerator.
  • "Private instances" together with "a lot of traffic to S3 or DynamoDB", which point to a gateway endpoint.

For example, if the question says "the private instances send a lot of data to DynamoDB and the NAT gateway costs a lot", the answer is a gateway endpoint.

Review question

A web application behind an ALB in us-east-2 serves product images to customers in Mexico, Brazil and Argentina. The images change once a week. Customers complain that the site loads slowly, and the bill for data out to the internet goes up every month. Which solution solves both things?

Next