Introduction
In some of my development roles, I was insulated from the costs of infrastructure, and test environments for engineering. Now that I actually run the infrastructure, I’m always looking for ways to reduce costs.
Luckily I have some experience identifying costs and implementing architectural changes that have save thousands of dollars a month.
Before we move forward, I don’t represent AWS in any way, nor do I make any guarantees about pricing.
Let’s Dive in.
Case Study: Running a Rest Server on EC2
We will be working with a classical client-server architecture.
A client connects to a loadbalancer over https(s), which refers the request to some hosts. This hosts are performing lookups on a database. We assume that this is a read-heavy system.
We will assume the EC2 instances are of type m4.xlarge, (Costing $0.20 per Hour each).
We will also assume that the DB is some flavor of SQL that is running in as a m5.large. The database contains 1 GB of Data.
Our Application serves 500,000 requests a day. The average response is going to be 2KB of data.

If we break this down, we have 3 components in AWS that could be where we are hemorrhaging money:
RDS - MySql - RDS Pricing consists of Data Transfers for Replication, the actual instance price, and the cost of Storage as well.
EC2 Instances - In this case we have three, and these have a cost per hour. Because we have 3 in this example, the rate is now $0.60 per hour.
Load Balancer - This has a cost to run, and tallies up the amount data you are transferring on your bill.
RDS
Relational Database Service is an AWS construct where a user can create instances to serve Postgres, MariaDB, etc for their application. When setting up the RDS instance, you will need to think through backups, read replicas, etc.
The cost model includes the instance itself, storage used, and outbound data transfer.
Breakdown of Cost Per Month:
Instance - $120
Storage - $0.08
Outbound Data Transfer - $2.61
Yearly Total: $1472.28
DynamoDB
If we are able to transform the datamodel to work better with DynamoDB (NoSQL), we can reap a lot of the benefits of DynamoDB:
Automatic Sharding
Automatic Redundancy
NOTE: It is not always recommended to convert to DynamoDB if your data model relies heavily on the relational nature of SQL. Additionally, doing this may be very difficult.
Lets talk about costs:
Outbound Data Transfer - $3.76 ($0.125 Per Million KB Reads * 30 per Month)
Storage Cost - Covered by Free Tier.
Yearly Total: $45.00
Savings
$1427.28 per year
EC2 Instance
EC2 instances require power on and power off. They are VMs — you can log into the machine; you can perform systems updates; etc.
Breakdown of Cost Per Month:
Running 3 Instances of m4.xlarge - $403.2
Yearly Total: $4838.40
Lambda
Lambda is an alternative to EC2, it is an ephemeral compute, meaning that it powers on, does its jobs, and then dies if it is not being used. This runtime can be powered by a docker container, but makes a lot of assumptions about the runtime. Lambda also provides ways to control Memory, CPU, and parallelism.
Lambda’s generous free model actually would cover all of these costs.
Savings
$4838.40 per year
Load Balancer
A Load Balancer is used to delegate work out to all of the EC2 Instances. There can be rules you can use to prevent access to certain paths, and you can add healthchecks to ensure all Ec2 Instances are up. Load Balancers are relatively cheap, but if you are forcing a lot of data through the LB, things can get pricey.
Breakdown of Cost Per Month:
Running A Load Balancer: ~$16
Data Transfer - ~$0
Yearly Total: $192
API Gateway
API Gateway’s free tier covers all of these costs, and provides the ability to send traffic to Lambdas.
Savings
$192
Full Savings:
Previous Yearly Price: $6502.68
New Yearly Price: $237 (wowzers)
Conclusion
While this architecture is very simple, it is very common and highlights some easy ways to start saving money on your infrastructure. In this case study, we saw how embracing AWS constructs, and using ephemeral compute can save your organization a lot of money.
As your organization grows, you may find that you will need to start supporting multiple production deployments, or even developer copies. By building out a well behaved system, you can make sure your infrastructure costs stay under control.
If you like this article, please subscribe. If you are wondering about other ways your organization may be paying too much for infrastructure, head on over to https://bytebelt.io and click Contact.