How Much Do Serverless / Managed Services Cost, and Is It worth It?
Cloud service providers are coming up with higher- and higher- level abstractions to free you from a lot of the tedium of building and running a backend.
But how much more do you pay for this ease?
On the database front, using RDS typically costs twice as much as running a database yourself on raw EC2 instances. A single 768 GB instance with 96 vCPUs costs $50,000 more per year on RDS than on EC2! If you’re thinking that this doesn’t apply to you because you don’t have such a big instance, it will, if you have a bunch of small instances instead of one big instance.
On the compute side, I’ve calculated the cost1 of using various levels of abstraction from FaaS at the top to serverless platforms like App Engine or Cloud Run at the middle to VMs at the bottom:
Let’s compare the highest level of abstraction, FaaS, with the lowest, VMs:
Ignore the difference in price between AWS and Google VMs; it’s because the EC2 VM has double the CPU. But even with that difference, both are a fraction the price of FaaS.
Let’s compare all the options in the table above:
Click the graph to open it in a new tab if it isn’t legible. Note that App Engine standard environment is off the scale at $149.
The conclusion is that abstractions come at a price. These should feed back into your architectural decision making. For example, if you’re starting a startup and you want to do edge computing, with an instance of your backend in each city to cater to users there, for low latency and regulatory compliance, you can’t afford $10,000 / month per instance. Because that multiplied by 100 instances costs a million dollars a month!
Does this mean that you should not use FaaS if you’re cost-conscious, such as a messaging app with millions of daily active users but no revenue? Not necessarily. The above is only a relative comparison. The conclusions it gives you are helpful, but not the complete picture. For that, you should do an absolute estimation for your product:
Take Telegram as an example. It has 36 million daily active users. Assume each user makes 100 HTTP requests a day. Let’s calculate how much it would cost if we use the costliest abstraction, which is FaaS. Let’s start with Google Cloud Functions. It offers different instance types with different amounts of CPU and memory. Let’s assume that we’ve optimised our code to use the cheapest. Then, GCF bills based on the time of execution, rounded up to 100ms. So let’s assume we’ve optimised all our functions to complete in 100ms. Assume also that each invocation returns 1KB. Incoming bandwidth is free, so we don’t need to consider it in this calculation. Taking all the above into account, GCF costs $84,000:
What if we use AWS Lambda instead of Google Cloud Functions? With the same assumptions, it works out cheaper, at $50,000.
$84,000 is actually a trivial amount to pay for a startup with hundreds of millions of users!
You should do a similar analysis for your startup to estimate costs. It will be inaccurate, but an order of magnitude estimation — is it $800/month? $8000? $80,000? $800,000? — is valuable for planning.
You should know what your costs are, and will be in the future, but don’t be cost-driven. Your job as a startup is to demonstrate business value, and you should use whatever technology helps you reach that goal the fastest. If you are miserly, others will move faster, and beat you. It would be like participating in a car race but driving slowly to conserve fuel, which is a guaranteed way to lose.
Each HTTP execution takes 100ms.
When it's done, the server receives another, at a constant 10 RPS 24x7.
If price varies based on location, we choose the cheapest location.
For GCF, Lambda, Heroku and Cloud Run, we use the biggest instance type available.
For App Engine (standard environment), we use the biggest class that has automatic scaling.
For App Engine (flexible environment), we match the 10GB and 6 vCPUs of Lambda.
For GKE, there's a per-cluster fee of $75 / month, which isn't included, since it doesn't increase with the number of nodes.