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.
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.
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
Put an SQS queue between them: the order service sends a message and returns, and the billing service consumes the queue at its own pace (scaling on queue depth).
Add a CloudFront distribution with the ALB as origin and long cache TTLs for the files. Downloads are served from edge caches, and the ASG stays small.
AWS documentation
Serverless website: MyBlog.com
A global serverless blog with CloudFront and S3 for static files, a public API on API Gateway and Lambda, DAX and DynamoDB global tables, a welcome email through DynamoDB Streams and SES, and thumbnails from S3 events.
Event processing
Event-driven patterns on AWS - Lambda with SQS, SQS FIFO and SNS and their dead-letter queues, the SNS fan-out, S3 event notifications and EventBridge, intercepting API calls with CloudTrail, and API Gateway writing straight to Kinesis.