Should I host my app in the Cloud
If you run an business, you probably hear a lot about cloud from many people - developers, friends, competitors, etc. Although Cloud became a very popular term in the last years, I've noticed that its meaning is often unclear, and people don't realize what are the benefits of applying this technology. Should your web app migrate to cloud? What benefits will you get by taking this step? Find those questions answered below.
What is Cloud hosting?
Before we jump into the advantages and disadvantages of cloud, let me briefly describe what what cloud hosting really is, and how it works.
In its early years, cloud hosting was quite similar to on-prem hosting. It offered you CPU, RAM and disk in exchange for your money. The crucial difference was how it was sold and implemented. In a traditional approach, you selected what you needed, and you paid for it for a month upfront. You got a server, and it worked. If the server was becoming too small for your needs, you needed to order a new server, have your web application moved, and all the data migrated. The server was also not redundant, so if it failed, your web app went down.
Well, cloud hosting takes all the described issues off the table.
Why is cloud hosting better?
Let’s take a look at some advantages cloud hosting offers.
It is billed based on a short periods - usually minute or hour. If you have more traffic during specific hours or days, you can scale up and down according to your needs and only pay for the period the servers were needed.
Side-note: the billing does not always need to be time related, but is always usage related. Ex. You might pay for the GB of storage, GB of traffic, e-mail sent, etc.
Easy to scale
The flexible pricing model brings another advantage with it. Imagine you have an algorithm that takes 16 hours to compute the results. I assume you can parallelize the computations. In such a case, you can order 16 new cloud servers (they are ready to use within minutes), compute the results in 60 minutes and then shut all the servers down. You pay for the 16 servers * 1 hour. The results are available faster, and your main server is not overloaded.
Your web app was mentioned on Reddit? If the app is well-prepared just launch a new server (it takes a couple of minutes) and split the load!*
*Keep in mind you have to be prepared to configure the server quickly and the app needs to be able to run on multiple servers.
Cloud servers are built from temporary (CPU, RAM) and permanent (disk) resources. The disk storage is replicated so you don’t lose data. In case of a hardware failure it's very easy to launch a new copy of your machine in a very short time. A new machine (CPU, RAM) is launched, and the „old” disk is connected to it.
This does not mean there is no chance of losing data. You still need to do backups and have disaster recovery scenarios in place.
Because all parts are virtualized and and easy to replicate, the risk of downtime is minimized. You can also (and you should if you have the opportunity) split the servers into several zones. Launch a redundant server in another availability zone and become independent of energy loss, connectivity issues, or fire in one of the Data Centers.
Be aware of some misconceptions
All the above advantages are sometimes misinterpreted, there are also some disadvantages of cloud hosting, and it's good to have them in mind:
- Cloud is expensive - compared with on-premise services it is always more expensive. But it is less prone to failure, and failures cost a lot.
- Cloud is hard to understand - there are dozens of different services with lots of options. The learning curve is very steep. Even a technical person could have trouble with properly setting up a production environment on the cloud.
- It is not a silver bullet - just migrating into the cloud won’t fix your uptime or scalability issues!
- Some software is not ready to run on the cloud (the architecture has to be done right).
- Cloud also has outages - but if your project was set up properly, it could recover faster by launching the services in another location.
Cloud hosting compared
Cloud vs shared
It’s like comparing apples to oranges. Shared hosting gives you zero influence on how your app is hosted. The resources are split between you and a dozen of other users. If one of the users is under attack or is causing a huge load, then your service is slowing down. Shared hosting is good for Wordpress or for some early days of a web app, but its definitely no good in a longer run.
Cloud vs VPS & on-premise
I already described the main differences above in the section named "Advantages of cloud". On-prem was the default approach to application hosting before cloud came in. So cloud is architected in a way to get rid of the biggest disadvantages of on-premise hosting. In all cases, the answer if cloud or on premises is better will depend on the nature of your service. Ex. if you have very predictable traffic, or high availability (SLA) is not required - on-premise might suit better your needs. It’s also cheaper in such cases*.
*It's worth mentioning that all major cloud providers have a free tier that is enough for most of the startups to start using cloud without spending a penny.
Cloud hosting redefined
It is important to highlight that all the advantages of the Cloud described above were introduced with the first years of cloud services. Services like Amazon EC2 (computing instances), S3 (block storage, ex. for storing files) were a huge improvement compared to the alternatives available at that time. Since the early days of cloud hosting, there is an ongoing process of adding more services that make it even better every year. I will mention only a few that are good to know if you have a web application.
Managed services - database, cache, etc.
All major cloud providers offer managed services that allow you to set-up a database, cache, message queue, and many more. Taking a database as an example: you select some properties, and your cloud provider is responsible for the uptime, backups, updates, scaling, etc.
Containers in the cloud (container orchestration)
Containers (Docker) allow you to pack your application into a box that can run on many providers and/or machines in the exact same way it runs on your computer. Containers are currently the go-to approach to deploying web applications. There is a huge set of cloud services like managed Kubernetes clusters or AWS Fargate, that allow you to set up and scale containers within minutes. Instead of managing virtual servers like EC2 instances, you tell Kubernetes/Fargate to run a container with N instances, and that’s all. Your cloud service will add/remove servers based on your current needs. If a server goes down - the containers will be immediately rescheduled to a new server. Container orchestration is almost always a managed service, so all the updates, maintenance, etc. is handled for you by the cloud provider of your choice (GCP, AWS, Azure).
Serverless goes one step deeper into the abstraction levels. Serverless is an approach to cloud services that abstracts the meaning of servers. Let us take AWS Lambda as an example. Suppose you have a SaaS service that is computing some analytical data to show to the user. Computing the data is heavy and needs to run once a day. Earlier I have mentioned that you can order a server instance, compute the results, and then delete that instance. With Serverless you define the code that should be run and execute it. You pay for CPU and RAM usage calculated with accuracy to 100 milliseconds! You do not need to think about instances, servers, anything.
Serverless also works for web applications. You can build your whole application using the Serverless approach and each HTTP request will be handled by the service. All milliseconds are counted, and you are billed for the used time. If there are no active users at night or during weekends - you don’t pay for these hours! If a lost user accesses your service on Saturday - he will be served as usual. If your website goes viral - everything will be handled. Your cloud provider will scale up and down exactly to what your service needs at the moment.
When to use cloud hosting?
In most cases, cloud will be a perfect fit for a startup. When the app is built with cloud in mind, and engineers do the right job, you will be able to launch your service using only the free tier options, and who would not like to host an app for free? It will also allow you to scale more quickly when you get traction.
In the case of more mature businesses switching to the cloud will bring similar benefits. We have migrated some of our customers to Cloud in order to make the infrastructure more reliable, allow them to scale up more quickly, and also make the whole setup more secure.
When NOT to use cloud hosting?
On the other hand - you might not be able to fit into the limits of the free tier, and setting up paid services may become expensive in the early days. Using on-prem will be much cheaper, but you still should aim to switch to the cloud at some point in time - when scalability will be required.
There are industries where the number of users is limited and known. If you build a service for students in Wrocław, and it does not make sense to use it outside of the city - then the limit of users is small enough to not bother about quick scalability. A simple VPS server will be enough for you (but you will need a sysadmin).
You should pay attention to the legal aspects of keeping user-related data. Ex. in Europe, the data of users must be stored inside Europe, so you are not allowed to use an American data center to host your web application.
If you decide to use cloud as your hosting infrastructure - it might be worth to build your web app in a cloud native approach - this means you can relatively easily switch to a different cloud provider when needed. This is not very likely to happen, but it does not require much effort to be prepared.
I have discussed a bit about the advantages (flexible pricing, easy to scale, redundant, high uptime, less hardware fails), and disadvantages (more expensive, harder to understand, not a silver bullet, also has outages) of the cloud. Additionally mentioned the basics of the newer cloud offers like serverless and containers. Keeping all that in mind I would advise Cloud as the first choice for most of the web applications, but only if the application architecture is ready for it. People tend to choose an on-prem solution because it's cheaper than cloud - well, it is usually not true when you count in maintenance costs. You have to update the systems, keep an eye on security, do backups, etc. With a properly set-up cloud (also requires expertise) you will get all of this for free.