Skip to Content

Microservices and offloading downloads

A microservice architecture where each service is built its own way, synchronous and asynchronous patterns between services, their challenges, and how adding CloudFront offloads software update downloads from EC2.

Microservices

The goal is to move to a microservice architecture:

  • many services talk to each other directly through REST APIs;
  • each service can have its own architecture, in whatever form and shape suits it;
  • each service gets a leaner development lifecycle: its own team, deployments and scaling.

Microservices: users resolve each service name with Route 53 and call it over HTTPS; service1 runs on ECS behind an ALB with DynamoDB, service2 is API Gateway and Lambda with ElastiCache, and service3 is an EC2 Auto Scaling group behind an ALB with RDS; each service is built in the way that suits it Microservices: users resolve each service name with Route 53 and call it over HTTPS; service1 runs on ECS behind an ALB with DynamoDB, service2 is API Gateway and Lambda with ElastiCache, and service3 is an EC2 Auto Scaling group behind an ALB with RDS; each service is built in the way that suits it

Each service picks its own building blocks.

Talking between services

  • Each microservice is free to follow its own design.
  • Synchronous patterns: API Gateway, load balancers. The caller waits for the answer.
  • Asynchronous patterns: SQS, Kinesis, SNS, Lambda triggered by S3 events (and EventBridge). The caller hands off the work and carries on, so a slow or failed service doesn't block the others.

The challenges

  • Repeated overhead to create each new microservice.
  • Hard to optimize server density and utilization.
  • The complexity of running many versions of many microservices at once.
  • Client-side code that must integrate with many separate services.

Serverless patterns solve some of these:

  • API Gateway and Lambda scale automatically and billing is per use, so a little-used service costs little.
  • An API can be cloned in a few steps to reproduce whole environments.
  • API Gateway can generate client SDKs from its OpenAPI (Swagger) definition.

Offloading software updates

An application on EC2 distributes software updates now and then. When a new update comes out, a flood of requests downloads it and the traffic is very costly. The constraint is to not change the application, while cutting cost and CPU.

Offloading software updates: CloudFront is added in front of the existing load balancer; it caches the static update files at the edge, so only cache misses reach the ALB and the EC2 Auto Scaling group, which reads the files from Amazon EFS and can run fewer instances Offloading software updates: CloudFront is added in front of the existing load balancer; it caches the static update files at the edge, so only cache misses reach the ALB and the EC2 Auto Scaling group, which reads the files from Amazon EFS and can run fewer instances

Put a CDN in front; leave the app alone.

Put CloudFront in front of the ALB:

  • no change to the architecture or the application;
  • CloudFront caches the update files at the edge: they're static and never change, a perfect fit;
  • the EC2 instances aren't serverless, but CloudFront is, and it scales automatically;
  • the ASG scales out much less, which saves a lot on EC2, on availability effort and on network cost (data from CloudFront to users is cheaper than from EC2, and origin fetches to CloudFront are free).

It's a low-effort way to make an existing application more scalable and cheaper.

Real-world examples

  • A game studio ships a 4 GB patch to 300,000 players in an hour. With CloudFront in front of its download servers, the origin serves the file a few hundred times instead of 300,000.

Exam tips

  • "Decouple microservices, one shouldn't wait for another" → SQS, SNS, Kinesis or EventBridge between them.
  • "Microservices, pay only when used, little to manage" → API Gateway + Lambda (or Fargate).
  • "Large static downloads overload EC2, can't change the app" → CloudFront in front of the existing origin.

Common traps

  • "Scale the ASG further to serve the update." It works but costs more; caching static files at the edge is the cheaper, simpler fix.
  • "Microservices must all use the same stack." Each service chooses what fits it.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt