Designing Cost-Optimized Architectures on AWS: Right Sizing, Serverless, Storage Tiering, Network Savings and Real Examples
Cost Is a Design Decision
Most savings do not come from discounts. They come from architecture choices: the right service, the right size, the right time, the right storage tier and the right network path. A cost-optimized design meets the requirement at the lowest price, not just the lowest price.
| Cost lever | Question to ask |
| Service choice | Is there a managed or serverless option that removes idle cost and operations? |
| Size | Is the capacity close to actual need? |
| Time | Does it need to run 24x7? |
| Pricing model | Can the baseline be committed and the rest be Spot or On-Demand? |
| Data | Is it in the cheapest suitable storage class, kept only as long as needed? |
| Network | Does traffic avoid NAT, cross-AZ and internet egress where possible? |
Compute Optimization
| Technique | Details |
| Right-size | Use Compute Optimizer. Many instances run below 20 percent CPU. Move to a smaller size or family |
| Graviton (arm64) | Often up to ~20 to 40 percent better price/performance for supported software (EC2, RDS, Lambda, Fargate, ElastiCache) |
| Auto Scaling | Scale in at night and weekends. Scale on demand metrics |
| Spot | For stateless, batch, CI, EMR task nodes, containers. Diversify types and AZs, use capacity-optimized allocation |
| Schedules | Stop dev/test outside working hours (can cut ~65 percent of the hours) |
| Savings Plans | For the always-on baseline |
| Burstable T | Cheap for low steady CPU. Watch credits |
| Containers | Pack many tasks on fewer instances; Fargate Spot for tolerant tasks |
bash
# EventBridge Scheduler rule idea: stop tagged dev instances at 20:00 on weekdays
aws scheduler create-schedule --name stop-dev-nights --schedule-expression "cron(0 20 ? * MON-FRI *)" --schedule-expression-timezone Asia/Kolkata \
--flexible-time-window Mode=OFF \
--target '{"Arn":"arn:aws:scheduler:::aws-sdk:ec2:stopInstances","RoleArn":"arn:aws:iam::123456789012:role/scheduler-ec2","Input":"{\"InstanceIds\":[\"i-0abc123\"]}"}'
Serverless vs Containers vs EC2: Economics
| Workload | Cheapest usually | Why |
| Low or spiky traffic API, many idle hours | Lambda + API Gateway/ALB | Pay only per request, zero cost when idle |
| Steady 24x7 high traffic | EC2 or ECS on EC2 with Savings Plans | Per-request pricing becomes more than a busy server |
| Variable web app, small team | ECS/Fargate (+ Fargate Spot where possible) | No node management, scale to demand |
| Nightly batch | Lambda, Fargate, or Spot via AWS Batch | Run only when needed |
| Always-on small utilities | **Graviton t4g or a small Fargate task** | Low fixed cost |
Break-even idea: Compare cost per million requests on Lambda at your memory and duration against the monthly cost of the instances needed for the same load. The crossing point depends on your numbers. Calculate before deciding.
Storage Optimization
| Technique | Details |
| S3 lifecycle | Standard → Standard-IA (30 days) → Glacier (90+) → Deep Archive; expire old versions and logs |
| Intelligent-Tiering | Unknown access patterns, no retrieval fees |
| Delete incomplete multipart uploads | Lifecycle rule AbortIncompleteMultipartUpload |
| EBS | gp3 instead of gp2, right-size volumes, delete unattached volumes, lifecycle snapshots, snapshot archive |
| EFS | Lifecycle to IA/Archive; One Zone classes for non-critical data |
| Compression and columnar formats | Parquet + Snappy shrinks storage and query cost |
| CloudWatch Logs | Retention, Infrequent Access class, export to S3 |
| Data retention policy | Delete what the business does not need |
Database Optimization
- Right-size instances using Performance Insights and CloudWatch
- Reserved instances for steady RDS/ElastiCache/Redshift/OpenSearch
- Aurora Serverless v2 for variable load, stop dev databases or snapshot-and-delete
- DynamoDB: on-demand for spiky, provisioned with auto scaling for steady, Standard-IA table class for rarely read data, TTL to delete old items
- Use read replicas or cache instead of scaling the primary up
- Redshift Serverless or pause clusters when idle; use S3 + Athena for rarely used data
- Choose Single-AZ for dev, Multi-AZ for production
Network Optimization
| Cost source | Savings |
| NAT Gateway (hourly + per GB) | Add S3 and DynamoDB gateway endpoints (free); interface endpoints for heavy AWS API traffic; avoid routing big downloads through NAT; one NAT per AZ only in production; consider IPv6 and egress-only IGW |
| Internet egress | Put CloudFront in front (lower per-GB price, caching), compress, keep data in the user's Region |
| Cross-AZ traffic | Keep chatty components in the same AZ where availability allows; use zone-aware routing; prefer AZ-local replicas |
| Cross-Region transfer | Replicate only what you need, compress, schedule |
| Public IPv4 addresses (billed) | Remove unused public IPs, use ALB/NLB shared addresses, IPv6, private connectivity |
| Transit Gateway data processing | Use peering for a few large flows if suitable |
Example 1: Reduce a Web Application's Bill
| Before | After | Effect |
12 x m5.xlarge On-Demand 24x7, 20 percent CPU | Auto Scaling 4 to 8 x m7g.large, Compute Savings Plan on the baseline | Fewer, smaller, cheaper chips, big reduction |
| All images served from EC2 and S3 over the internet | CloudFront caching in front | Lower egress and origin load |
| NAT Gateway carries all S3 traffic | S3 gateway endpoint | NAT data cost drops sharply |
| Dev and test run all night | Scheduler stops them 20:00 to 08:00 | About 50 to 65 percent fewer hours |
| gp2 volumes and 3 years of snapshots | gp3 and 60-day snapshot policy | Lower storage cost |
Example 2: Data Pipeline
| Before | After |
| Always-on large EMR cluster for a 2-hour nightly job | Transient EMR (or EMR Serverless/Glue) started per run, Spot task nodes |
| CSV in S3 Standard queried by Athena (full scans) | Parquet + partitions, older partitions to IA |
| Logs in CloudWatch forever | 30-day retention, export to S3 with lifecycle |
| Redshift 24x7 for a monthly report | Redshift Serverless or Athena |
Example 3: Low-Traffic Internal Tool
text
Before: 2 x m5.large in 2 AZs + ALB + RDS Multi-AZ = about a few hundred dollars a month for 20 users
After : S3 + CloudFront static front end, API Gateway + Lambda, DynamoDB on-demand
= a few dollars a month, no servers to patch, still multi-AZ
Cost-Aware Design Rules
- Prefer managed and serverless when the workload is spiky or small
- Commit to the baseline, flex above it
- Delete data and resources on a schedule: lifecycle, TTL, stack deletion
- Use cheapest class that meets the retrieval need
- Measure cost per unit of business value (per order, per user)
- Tag, budget and review every month
- Do not sacrifice required reliability or security to save money: match the cost to the requirement
Practice Tasks
- Take a sample architecture (ALB, 6 EC2, RDS Multi-AZ, S3, NAT) and list 6 cost reductions with their risks
- Estimate Lambda versus a
t4g.small for 5 million requests a month at 200 ms and 512 MB
- Add S3 and DynamoDB gateway endpoints and show the NAT route is not used for them
- Create a lifecycle rule for logs: IA at 30 days, Glacier at 90, delete at 400
- Write a schedule that stops the dev environment at night and starts it in the morning
Conclusion
Optimize cost by design: right-size and use Graviton, commit to the baseline and flex with Spot and Auto Scaling, choose serverless for spiky loads, tier and expire storage, cut NAT, cross-AZ and egress charges with endpoints, CloudFront and co-location, and schedule non-production. Never reduce reliability or security below what the requirement needs.
Quick Summary: cost levers; compute techniques + scheduler; serverless/containers/EC2 economics; storage/db/network tables; three before/after examples; design rules.