Free lesson · 6:05

Why Self-Host? Cost, Control, and the Work You Take On

Self-hosting can cost a fraction of managed cloud services, and you pay the difference with your time and operational work. This lesson compares the two so you can decide which one suits your application.

0.1 · Why self-hosting?

Press play to watch this lesson.

Source code and course materials are included with enrollment.

Get the complete course

Lesson transcript

Taught by Milan Jovanović, from Module 0 of Pragmatic Self-Hosting: Foundations. Lightly edited from the captions.

When self-hosting is worth considering

In this lesson, we're going to talk about why you should even consider self-hosting. It's important that we have a good understanding of what we gain by running our own infrastructure. Now, running your own infrastructure can mean 2 things. In our example, we are going to rent the infrastructure from a VPS provider for a very affordable price.

But it could also mean literally running your own infrastructure in a home lab or inside of your company servers. And a good question to open up this lesson is, when does running your own infrastructure give you a good alternative versus using managed services from popular cloud providers like Azure or AWS.

What you pay for with managed cloud services

I'm going to assume that you're familiar with at least one of the popular cloud providers in the .NET ecosystem. These are going to be Azure and AWS. These are amazing platforms that make your life as a developer a lot easier. They offer many managed services that you can use for hosting your applications, for many popular databases and caches and messaging infrastructure, message queues, event brokers, object storage, They also solve some of the operating work for you, like automated backups and scaling on demand.

And the whole premise of using a managed cloud provider is having less infrastructure to operate. You may be familiar with the term serverless. This basically means that you hand off the server management to somebody else. And don't get me wrong, these systems are amazing, and I've personally used them on many projects. And a huge advantage of them is that they are very convenient to use.

They are also fairly reliable, as there are big teams working for these cloud providers that make sure that the systems are operational and working efficiently. However, to get all of these amazing benefits, you have to be prepared to open up your wallet. And the costs are going to be significantly greater than if you were self-hosting.

And the reason for this is simple, you pay for the infrastructure, you're paying for the operational work, you're paying for all of these managed features that they are offering. And on top of that, these companies still have to make a profit.

The self-hosted alternative

So keep that in mind and then ask yourself, what could an alternative look like? What if I don't have to learn about all of these managed services, how to set them up, how to configure them, how to connect them to each other, what to do if something goes wrong? What if I could just use the fundamental services that are the core building blocks of most of my applications anyway?

These are going to include your executable application and its runtime, usually a database, possibly a cache, a message broker, and some of the other supporting components that you will need to run pretty much the majority of your production applications. And this alternative is renting a virtual private server or any type of barebone machine from a server provider and running your control plane on it.

In this course, we're going to be using Dokploy as our control plane. It's going to help us manage and deploy our applications to the server infrastructure that we are renting. Almost all of the components that we're going to use throughout this course are going to be free or are going to have a free open source alternative that you can also self-host.

The real cost of self-hosting

Now there's no such thing as free lunch. And because these things are free, you pay with your time and the operational work needed to manage this infrastructure. However, this can cost a fraction of the bill that you would pay for the same setup with a cloud provider. And I'm not exaggerating when I say that self-hosting can be 10 times less expensive than when using managed services.

What self-hosting means in this course

So what does self-hosting look like in this course? Self-hosting means running our application and its supporting services on a server that you rent and manage. The hosting provider is going to operate the physical infrastructure that we need. And this is going to be in the form of CPUs, RAM, and disk storage. We can choose which operating system we want to run on the server, which applications we want to run.

We're not limited in any way by a specific runtime. And because this is a foundations course, we're going to operate our application and its supporting services all on the same server. This comes with some benefits like reduced latency because they are all co-located on the same network and with obvious disadvantages like a single point of failure.

We're going to discuss some of the many ways we could solve this throughout this course.

What you control when you self-host

Self-hosting gives us more control over cost and performance. We get granular control on which servers we are renting, where we can fine-tune the amount of CPUs, memory, and storage, and other system resources that we need so that you only end up paying for the capacity that your applications actually need and use. Whenever you need more resources, you can easily scale up or even scale out your server infrastructure to support your growing workload.

With self-hosting, you have complete freedom to run the exact stack that you want in a production environment. You get to choose which runtimes and service versions you want to run. Whereas with a managed service provider, you are tied to the choices that they offer. You decide how your services connect to each other.

Are they going to be on the same physical server and communicate through a local network? Are they going to be on different servers and communicate through an encrypted channel over a virtual private network? You can control who can reach which service and if communication between some applications can be one-way or bidirectional.

What the course builds next

This course is going to teach you enough of the operating model for self-hosting so that you can make the best decision for your application and systems requirements. In the upcoming modules, I'm going to show you how you can build a repeatable system that allows you to deploy and operate your applications in production with confidence.

We're going to build an automated CI/CD pipeline, secure access to your administration control plane. All of our public services will use HTTPS, and I'll show you how you can verify your production releases in an automated way. We're also going to handle managing and updating our system, rollbacks in case of bugs so that you can easily go back to a previous application version, and of course automated backups so that you can recover from any potential crashes.

At this point, you are probably thinking all of this sounds nice, But what is this actually going to look like in practice? And that's exactly what I'm going to show you in the next lesson, where you are going to see the finished application in production and the complete system behind it that we are going to build from scratch.