Not sure if this is the right channel for this sor...
# random
e
Not sure if this is the right channel for this sort of question, but couldn't find a better one. So, here it goes. I've been hearing Serverless is good. But how different or better is it in comparison to Google Cloud run? And how do you estimate the cost of hosting an application in Serverless? Would greatly appreciate if someone could shed light on this or point to any content that can help me with it.
l
I have taught myself serverless using AWS Lambda + serverless.com for a side project I am currently working with. “Good” is relative. It has it’s pros and cons and a different way of thinking about it. I have not used Google Cloud - so I cannot compare — but the cost of using Serverless is almost negligible for most cases. For example, if I was to build this using the traditional stack, for the most basic use case, I’d need to have atleast 2 x EC2 instances + 2 x RDS instances powering my app - which would cost me ~ $150 - $200 / month. Compared to that, Serverless I am on the free tier and even with about 2000 - 3000 users at which point I imagined I’d have to scale up my traditional stack, with Serverless, I’d probably pay about Rs. 500 / month. Again, it varies from application to application. So there is no one answer to this. Serverless is cheaper for my current use case - but might be more expensive for yours. Also, I am using DynamoDB and I had to really unlearn a lot of things even with lots of experience with MongoDB — so that cost you’ll have to bear in terms of time, trial & error to get your architecture right.
👍 3
q
I've used Nextjs for a serverless JamStack application and the regular MERN stack. I'll tell you what, while I won't comment on the performance, coz that boils down to how you write the code. As far as the cost associated is concerned, don't let the MERN stack stop you from building applications cuz it's expensive. There are tools that make it relatively cheaper, for example Atlas: cloud mongo dB Cloudinary free tier: hosting images/static Mailgun's node email api free tier: sending signup/forgot password etc, email Github for source control - completely free Github actions for CI/CD pipelines (free tier) EC2 free tier to host with elastic load balancer, private IP and SNS setup to alert you when you have extra traffic so that you can scale it up and down The cost you incur in this setup (atleast until you start generating enough traffic and income with your project to justify spending more) wil be about 300-400 rupees per month. Ultimately, I think for the best case scenario, you should package your app with docker and K8 + rancher if you want to stabilize and control your monthly spend more. In this case, you only spend money on monthly EKS or Google's Kubernetes setup, whichever you choose.
👍 1
e
Thank you @loud-glass-33663
Really have to consider the time taken to learn.
@quiet-midnight-20665 Thank you for providing a clear picture. This is very useful.
m
need to disambiguate some things: First Cloud Run is technically "serverless" because it ticks the serverless tenets: • no need to manage servers • scales automatically (in/out) • price per usage • fault tolerance I'm going to assume that by "serverless" you mean "Functions as a service" (refered to as "serverless functions"/'FaaS") such as AWS Lambda/ Azure Functions / Google Cloud Functions. Cloud Run is essentially serverless containers ie you provide a container image and Google will run it for you. AWS' equivalent of this is Fargate. In contrast, serverless aka Functions as a service accept a function or collection of functions as a zip package and are expected to have some constraints: typically the run time of serverless functions is limited where as serverless containers do not have execution time limits. there's no better - these are two fundamentally different ways of operation. Do you have a task which runs for a short period and can be invoked at any time? Serverless Functions is the way to go. Do you have tasks which run for longer periods of time, or cannot have arbitrary time execution limits? Serverless containers is the way to go. Cost depends on the cloud provider but Serverless Functions, most providers have settled for a unit called "GB-seconds" which is the number of seconds a functions run multiplied by how much RAM the function has been allocated. These are multiplied by number of times a function is invoked. To give you an example, if you have a function which runs every hour to send a chunk of emails, and this function takes 10 seconds to run and needs 128MB of RAM, per Google's pricing, this function would be free if you do not have any other functions because Google doesn't charge for the first 2 million invocations, but this function will be invoked 720 times a month (24 times a day, 30 days). Assuming you have already exceeded the 2 million invocations limit, then would have to calculate the cost: the pricing for this is detailed at https://cloud.google.com/functions/pricing So assuming the function takes 256 MB of RAM, then the function invocation would cost ($0.0000025/4 * 720*10) =~ $0.0045 per month (why divide by 4? GB-sec is 0.0000025, we need only 256MB. Multiply by 10 because each invocation runs for 10 seconds). I did not consider GHz-sec but you can find more details there.