AWS costs for a small web application
“How much does it cost to run a simple web-app for my startup?” you might think. In this blog post, I will show you what is the cost of basic components that your startup might need. I will be using AWS as an example. I will also explain what are the pros and cons of each component and point alternatives. After reading this you will have a better understanding of how much does it cost to run simple services in the AWS cloud.
What I mean when I say a “simple web-app”? What are the components? I mean a Rails application (serving as an API, but could be serving HTML as well), some SQL database to store your data, perhaps a frontend application, background processing of some kind to offload hard to work.
I’m going to optimize mostly for cost, although not fully. For example, I could be running my DB instance on an EC2 machine, manage backups, etc. It would be the cheapest solution (on AWS) but I consider this a relatively difficult task with extremely high risk – losing data. I will be discussing the cost aspect of each solution.
Computing power
We will have to run our application somewhere. There are many ways to achieve this within the AWS ecosystem.
You can buy EC2 machines (a.k.a. Computers Connected to The Internet). You can buy a managed service like Lightsail or Beanstalk. Such service runs your application and manages a few (or a lot) things for you. This costs money. Finally, you may run Amazon Lambda, but this is a pretty hard-core setup to run a web application.
I’m choosing EC2 machines which I buy on the Spot Instances market. These are EC2 instances that are currently doing nothing on AWS infrastructure and you can buy them for a fraction of the price of original instances. The savings range between 50% up to 90%!
There are drawbacks. Such an EC2 instance could disappear at any time. You may think that this makes them unusable, especially if you run an API app on them. If you set up your infrastructure right, though, this will work just fine. I will discuss it in a separate chapter.
So what are the costs ultimately?
An m1.xlarge
instance (4 cores, 15GB of RAM) has a 90% discount on Spot Market
(the biggest you can get). It is now $0.035/hour which is roughly $25/month.
These instances provide reasonable computing power and enough memory to run a
Ruby on Rails app with a few background processes on it and other things.
As a side note: the cheapest instance you can get, t3.nano
(2 cores, 0.5GB memory)
is $0.0016/hour – $1.15/month.
Database
Most of the work I did in the past was programming, but I liked dev-opsing too. Running your DB manually is something I consider too difficult to do.
Why?
Your database is the “heart” of your application. It stores data, which I consider one of the most precious things you will have. Your customers trust you take care of their data with caution. You have to have some backup done regularly. You will also need the DB to be highly available. There are just so many things to break!
Luckily AWS has a managed SQL database – it’s called RDS. The cheapest DB you
can have there (which is ok for start) is db.t3.micro
at $12/month.
It runs on one core (2 threads per core) and has 1GB of memory. You get
automatic backup, scaling, configuration management, monitoring, all those
things that are tricky to set up and maintain. Unless you need something very
specific or your scale is big enough to have considerable savings here don’t
run your own SQL.
If you reserve the instance – that is if you commit to buying it for the next 1 or 3 years, you will pay less. If you pay upfront you will pay even less. That is between 30-50% savings.
Running your application
We decided to run our apps on EC2. You have at least two options here.
- Manage your instances on your own
- Rely on ECS – AWS solution to run and manage dockerized apps
Unless you want to get your hands dirty I think it’s much safer to go with option 2. The cost is very low and the gains are significant. You solve the problem of deploying, monitoring, logging. Setting this up on your own is a real pain in the ass because there are a lot of moving parts that can break.
The most significant cost associated with this option is the router, namely Application Load Balancer. It costs $16/month and plays nicely with the infrastructure if you make good choices. The role of the router is to move the traffic from entry point like your domain to your application instances. For the price, you get automated deployments via Blue/Green deployments.
When running your service via ECS you also get logging to CloudWatch and automatic management of running processes and the ability to easily scale things.
Final cost
With EC2 spot instances, you can get your computing power for little money. To achieve reliability you can duplicate your instances so when one instance dies you are still up. You can also mix spot instances with regular On-Demand ones for more stability.
Add a database and a load balancer and you have the cost of running a simple service.
I also added Redis to show you how much a managed Redis instance costs. You could always run your own on EC2, but again: if you look for stability I think it’s an overkill considering that it’s 13 bucks/month.
Component | Price |
---|---|
EC2 instance | $25/month for 4CPUs/15GB RAM |
Database | $12/month for 2CPUs/1GB RAM |
Load balancer | $16/month |
Redis | $13/month |
There are three additional things to mention.
The most straightforward one is: you will be taxed accordingly.
You will probably want to have some staging environment. Otherwise, there is no way to test things, especially when it comes to changes in infrastructure. For example, if you were to update your RDS MySQL version from 5.x to 8.x, you’d want to have two DB instances, one for staging and one for production, so you test how the update goes. This effectively doubles your initial cost.
There is also usage cost, which is low at the beginning but will increase later on as your product grows. It depends on your use-case very much, but you can assume it’s gonna be an additional 10-20% on top of the total cost for the simple use-case.
I hope this gives you a better understanding of what to expect from running your service similar to the one I described.
Illustrations from Icons8