so I made a video the other day about what type of services you may need when you're building out a SAS product and I have a bunch of different services that you could potentially pay for or you could try to roll these yourself or just kind of Do Your Own Thing now a couple people have commented saying that this is kind of crazy like you don't need all these services to run an application um one person left a comment that you could actually run everything just with a single VPS and I think there's some truth
behind you know you don't need all these services but also at the same time running your own stuff on your own little VPS server is also not the best solution for production system in my opinion let's just go ahead and break down some of the costs of something for example like hosting on versel let's say you actually have a product that's getting some users how much does it cost to host monthly I think their pricing plan is about 20 a month plus whatever usage you may go over with limits okay so 20 a month if
you were to think about the average software engineer's salary let's let's look at that real quick so if I do a quick little Google search this indeed.com says it's about this much so 100 116 000 a year so let's just go ahead and break that down into 52 weeks and there's 40 hours in a week so this is their average uh pay per hour 56 dollars an hour so if you kind of approach this from a business standpoint it costs 56 dollars an hour to pay someone to build software now again I'm scoping everything I'm
talking about in the United States because that's where I live that's what most of my content is based around but with that being said if it costs 56 dollars an hour not including whatever overhead you may have when you hire someone to your company it's very hard to justify not using one of these Services right so how much time and effort would it take for you to set up your own CI CD pipeline process that hooks in the GitHub to automatically build and deploy your code to your own VPS service when someone makes code changes
if it's less than an hour if you're that good you can do it in less than an hour and do it perfectly then yeah you may justify being able to not pay twenty dollars a month for a hosting platform like Brazil or netlify but in reality coding is never simple right so 56 dollars an hour how many months of versel Hosting would that be that's about two and a half months so can you justify building your own hosting Pipeline on a VPS that's five dollars a month just so you can save 20 a month I
don't think so so hosting 20 a month for versel or most of these services or you can do it yourself for really cheap with SST so let's move on to logging again in a production system you need to have logging if you don't I don't know how you're checking to see if stuff goes wrong how many API endpoints are getting hit who's hitting what APM points if a user contacts you and says hey I'm having issues doing this feature in your application if you don't have a way to actually look at your logs then I
would say that you're not running a production ready system now there are ways to basically set up logs for free for example you can set up the elk stack which is elasticsearch that kind of Aggregates all your logs into a nice search index and then you can use log stash that lives on your VPS or your dedicated server to collect the logs and ship them to elasticsearch and you have Cabana which is a nice UI that basically allows you to do all this stuff now unless you're really good at servers in like system administration logging
into the VPS and setting this stuff up and connecting it to elasticsearch and making sure Cabana is configured correctly you are guaranteed to spend more than an hour trying to set this stuff up unless you've already done it before so again it's probably worth money paying another service 20 a month or however much these Services cost a month sometimes it can be like 100 a month to be able to search through your logs and get beautiful analytic graphs filters and whatever aggregations and like dashboards so you can actually get a nice view of what's going
on in your system and you set up an entire production ready logging system in less than an hour or less than two hours because again every hour you're paying an engineer 56 dollars an hour that is money that you could actually be spending on building out your product or your features you kind of have to keep on on weighing this out right if you're not using a pre-existing service to kind of do some of these things you're paying an engineer to do them for you and there's a lot of overhead cost with building your own
system right for example if you're hosting your node server on a VPS you have to keep in track of security updates that need to be done on that VPS right you probably set it up with an Ubuntu version new versions come out you got to update those keep them up to date your node stuff has to be updated you know versions have to be updated which is going to involve you kind of going to the machine trying to figure out a way to like update those things without affecting users maybe you just want to turn
the node service off do the updates and turn it back on but again every every hour you spend doing these manual processes is an hour that you wasted that you could have been using to build out cool features in your application now databases this is something I would never recommend you hosting yourself on your own VPS instance although you could it just seems risky to me if you're the type of person who says that you want to do a VPS and host like a postgres database on your VPS and connect that to your node instance
that's running on the machine same machine there's a lot of security things you have to consider to make sure that no one can ever get access to your database make sure you have correct firewalls set up make sure you have correct security set up and password set up it's just a lot of overhead like I said and you're not going to know that if you're a beginner you have to kind of learn that over the years that it's going to take you much longer than an hour in my opinion and just using a pre-existing service
to give you a already running postgres database for example you can use super bass which has a postgres instance on it you can use Planet scale I'm going to update these because I think for some reason I put databases instead of actual Services you could use Atlas okay and again these are going to cost 20 bucks a month as well so now we're at 20 40 60 a month to pay for some of these core things that your production system will need and right then and there if you can say that you have saved your
your developers an hour or yourself an hour of working then it already pays for itself it already pays for itself right now some of these things like you have to have like strive for payment processing you can't really get around that unless you find something else if you're the type of person who says I'm gonna host my thing on a VPS and I'm going to SSH into it all the time or run a script that that connects to the box and kind of does a git pull and then restarts my node server like yeah like
you can do that but honestly like why would you want to do that there's Services out there that automatically deploy directly from your GitHub repo when you make changes so I think it's kind of a waste of time to build your own deployment pipeline when you could just use something like versel or netlify or or digital ocean I believe um let me go up to hosting real quick I believe digital ocean I like digital ocean a lot digital ocean they have like app deploy which basically hooks in to your CI CD pipeline to do deployments
when stuff finishes let me go ahead and add um Firebase people got mad they didn't add Firebase here but Firebase is again a service like a backend as a service that has authentication in it Firebase there's also like tons of Google Cloud stuff go ahead and add like Google gcp just to kind of update this diagram as I'm going through it but my My overall point I'm trying to make is if you're in the comments talking about how like you would save like why would you use all these services like seems like a giant um
it seems crazy honestly the setup that it takes once you have these Services set up is just hook these to your credit card and they're just gonna charge your credit card every month and once you have this thing integrated with your application there's not much additional overhead needed you have your actual running production system hooking into these existing Services right it's kind of like a set it up once and you forget about it a lot of people argue that like you should do your own auth like you shouldn't be using an auth service um which
works okay I mean like for example if you're using like Ruby on Rails or using like Django I think there's something called Adonis JS which is kind of like a laravel thing for node which has um authentication built in like with social authentication and stuff of you cannot use an existing auth service if you want to but I will say that like you gotta kind of make sure you're doing auth correctly I will say that personally when I log into a new website if they ask for email password authentication and that's the only option they
have I won't even use your application I would rather have social media login okay and you can achieve that with next auth like you don't have to pay an off service to kind of achieve that but if you're the type of person who wants to have email password login I would say that this is where you get into like Realms of like you got to make sure you're doing this right because if you screw it up you can get into a lot of legal trouble for example I worked at a company when I first started
learning about web development where all the passwords in the users table or just plain text passwords as an intern I was actually able to go in and I could see all of the passwords for thousands of users they weren't doing any type of decrypt or salt on the passwords they were just plain text passwords and that made me realize that I'm sure there's tons and tons and tons of companies out there who are row rolling their own off who aren't properly setting up how they're storing user credentials so me personally if I see a new
application and they don't have social media login I am not interested I'm not going to type in my email and password because honestly everyone uses the same password for every single application they have and if one data breach happens on a service then basically your password gets leaked and people can start trying all these other services with your email and password combinations and they can potentially get access to a lot of different things so I rather have the MFA set up with like Google and just log into everything using Google off that's another reason why
I like rolling your own stuff like you can do it if you're really smart and you want to waste your time doing that stuff but overall me personally I rather just reach for a service instead of doing it myself for example file storage if you're the type of person who wants to say that oh you could just host your own node service on a VPS how are you going to store your files let's say you allow the user ability to upload files and you have one malicious user who decides that he's just going to keep
on uploading one megabyte file in a for loop on a script until he fills up your entire storage on your disk and then your entire VPS crashes because you don't have some type of infinitely scaling storage so like I personally would never store files directly on the VPS I would offload those to like S3 or some other type of file hosting services so it's like all these things you have to think about I feel like I'm just kind of repeating myself by now but like there's just a lot more that goes into it you could
save money by just using a VPS but you have to keep in mind that there's trade-offs you're going to be spending a lot of time doing your own stuff managing your own stuff maintaining your own stuff which is why you have to like make the decision to like use a service versus rolling out your own the last point I'm going to hit on about like why I would probably never host my own production system on a VPS personally node.js gives me a lot of anxiety when it's not running on serverless and it's mainly because if
your server either runs out of memory or crashes for whatever reason on an on-caught exception that means that every single person who's currently trying to write data into your API or like fetch data from the API is going to get disconnected until whatever hacky process you set up to basically restart that server kicks off for example you can use pm2 on your VPS to have it restart your node service if it were to crash but again every time your server crashes you're basically losing every single connection and every person who did that post request their
data is not going to be stored they're going to have some downtime so that's one reason why I really like hosting everything on serverless everything runs in its own like I don't want to say isolated runtime but every API request has its own CPU in memory so that if that requests were to fail it doesn't affect the requests of every other user let me show you a reason why I just typically stay away from just having like a dedicated node process running your server here we have an endpoint called hello and after half a second
it throws an error instead of a set timeout and other than that I mean it should return hello or high and you think as a developer you can say try catch and if any errors were to happen you can just go ahead and console log those and then I'm going to run my server with TSX here so we have a server that's running I can go ahead and go up here and click refresh I'm gonna hit the hello endpoint but now notice that it's dead the reason that it's dead is because when an exception happens
inside this set timeout callback it actually crashes your entire server okay so then you're relying on pm2 to restart your server so that other requests can continuously happen but all it takes if you have an API that has like hundreds of endpoints all it takes is one developer to accidentally write some bad code like this and literally your entire server is going to crash and I know there's ways to prevent this like you can basically say on unhandled rejections just go ahead and console log errors or I could just say like don't throw errors here
let's just go ahead and restart that again and I don't think this will crash next time that exception but I would say if you don't even know about this and this is probably a reason why you shouldn't be hosting your server on a VPS or you should be using some type of um you should probably shouldn't be using Express maybe you should be using nest.js that might have this already set up for you because these are things that can actually happen on your server more specifically let's say you're doing like CVS processing you're generating PDF
files and use a lot of memory on the machine and for whatever reason your node process dies then every user who's connected to your server also just loses their session okay so those are the things that kind of go into my thought process when people say oh you could just host your own thing on like a a digital ocean VM for five dollars a month it's like yeah you could but honestly I would never do that on a real production ready system where a client's paying you a ton of money to build something that's reliable
that is not the approach for doing that all right that kind of wraps up this video I just wanted to make a video to explain why a lot of companies reach out to third-party services to offload that work because when you have dedicated Engineers who are building a database hosting site or a file storage site it kind of alleviates a lot of the anxiety that you might have if you're doing that yourself all right that's it if you like this video give me a thumbs up comment subscribe press the Bell icon leave a comment below
if you have any uh thoughts about what I mentioned here and like always I have a Discord Channel you're welcome to join if you want to find a place to hang out and talk to some other developers have a good day and happy coding