I had the following options for deployment. The below point summaries the ways to deploy both the MERN stack and Django.
- Digital Ocean: All the 4 services in the MERN+Flask stack can be deployed in one single server and scaled up based on requirements. Digital Ocean does not have the pay per use model this means there are charges even if the VPS (Droplet) is stopped. You need to destroy the droplet to prevent subsequent charges. The cost is very deterministic, you can clearly know what is the maximum expense you will incur upfront. In terms of scaling, the Managed Postgres offered by Digital Ocean or MongoDB Atlas can be used. There also have Kubernetes cluster which can be used for deploying the MERN+Python stack as a microservice. They offer one-click setup for Django this comes with Postgres and Nginx configured. The static files can be hosted in their Spaces Object Storage for a minimum of 5 $ per month or you can use Cloudflare.
- Vercel: Vercel by the creators of NextJS offers hosting multiple languages including NodeJS and Python through their serverless functions. There are some limitations (currently 12) as to how many pages can be rendered on the serverside for free. It comes with its own CDN. For database either managed Postgres services or MongoDB Atlas can be used. Once you hit the hard limits your app stops functioning.
- Google Cloud Platform (GCP): Google offers 300 $ credit for 1 year which can be used across all their products. This is great when it comes to experimenting. The MERN+Python can be setup Google App Engine flexible environment (Standard environment does not support WebSockets currently). With the pay per usage model for the app engine, you get automatically scaling based on demand. The frontend can be hosted in Firebase which comes with its own CDN. MongoDB Atlas will be used. In the case of the Django, you host in Compute Engine (VPS similar to Digital Ocean) or app engine. Managed Postgres offered by Google can also be used. The app engine can be easily set up with CD/CI pipelines and also offers A/B testing.
- AWS: Similar to GCP however more mature and widely used in the market. Based on the availability of tutorials for learning and community support seems to be the best in comparison to GCP. The free services are of two types, free for 1 year and always free within limits. This means, unlike GCP you cannot test out all the products. Deployment can be done in 3 ways
1. AWS Serverless Lamda functions: This is a pay per use model and scales well. They can at a max run with about 3 GB ram and not to mention the timeout settings when it comes to long-running process you need to be careful not to exceed 15 mins.
2. EC2: This is a VPS offering. It can be easily scaled using managed Postgres, autoscaling groups, or managed Kubernetes.
3. Elastic Bean Stack: This is a service similar to the app engine where you configure and forget. The creation of various services like load balancing, EC2 instances, etc is managed by AWS automagically. You will need to pay for the cost of running any paid services created by Beanstalk.
- Heroku: This was the last option when it comes to quick and easy deployment. It’s free for 750 hours and comes also with WebSocket support. For the MERN+Pyton Stack, Vercel for React/NextJS (for CDN) and MongoDB Atlas can be used. For the Django, managed Postgres offered by Heroku can be used. It’s free up to 10K rows. Due to their managed services at a fixed price it is really easy to get started. However, I find it to be costlier when you upgrade from free. The hobby version costs 7$ for running the dyno and 9$ for managed Postgres. As for 1 GB ram dyno you need to pay around 50 $ per month and another 50$ for a database with dedicated 4 GB ram.
Both Google or AWS infrastructure comes with the following challenges:
- From Code to Config: You will be overwhelmed with the amount of configuration and different screens to setup and deploy each service. Keep in mind these interfaces seem to be constantly updated.
- Technicalities: Also the when it comes to managed services the updates get released according to predetermined schedules. However, there are options to have a custom runtime even in the serverless offerings.
- Vendor Lock-In: You will have to spend a significant amount of resources in case you move to a different service provider. Companies like Serverless might help in this process.
- Cost Determination: Without knowing how many customers will use your product and their subsequent number of requests, it will be very difficult to be deterministic about the cost. Not to mention you will also have to take into account the network charges.
When comparing all the options I think that the Digital Ocean offers a much safer bet where the cost can be determined upfront and the learning can be easily transferred even if you move to AWS, AZURE, GCP, etc as VPS is always same. As the product or service grows and the more services you can it can be switched to AWS/GCP. When it comes to testing Heroku and prototyping free is excellent.
Previous Post :
Next Post :