The Cheapest Way to Deploy Web Apps
Introduction This month I got my first bill for my google cloud platform. When I saw the bill, my first thought was "well, I am screwed, aren't I". It was like 6000 rupees ($70). I am a college student and there is no way in hell I can afford that. So I did what any self respecting college student would do and decline all the payments and started fresh. Armed with my prior experience, I started my crusade to find the cheapest and the most effective way to deploy my apps. Which cloud platform to choose Choosing the appropriate cloud platform, is the most important decision one can make, I mean they are the ones making the bills at the end of the day which you have to pay. So it is essential that every developer does his in depth research about these platforms, before making a decision. Backend - I think Google Cloud Platform is the best for beginners. It is cheap, not that complicated to use, has a very generous free tier, and most importantly it asks before it charges your charges your credit card. Also while using it make sure that your storage and cloud run region are same and comes under the free tier of GCP, GCP charges extra for cross region transfer. Frontend - Vercel is the best choice if your are using NEXT.js or any react app. One can deploy his/her frontend app easily in just 2 clicks with continuous deployment out of the box (any changes in main branch of github repo is automatically reflected there). Here is the fun part, you don't even need to enter your credit card details to get started, I know I haven't. Why Seperate Frontend and Backend deployment You must have noticed I choose different platforms for frontend and backend deployment. You might be wondering why do such a thing in the first place, isn't it better to have every thing on one place ?? The reason I do it because first it makes my work much more manageable, knowing that my frontend and backend seperated. But the more important reason is the specialized advantages that platform like Vercel provide for heavier frontend deployment (like static-site optimization, CDNs, caching) which platforms like Google Cloud Platform don't provide. Google Cloud Platform, Heroku, AWS provide dynamic runtimes, scalability, database connection which are more tailored towards backend needs. Having frontend and backend deployed seperately means that you don't have to worry about potential problems that might occur when you try to scale either. What programming language to choose I am of the belief that developers can choose whatever programming language to choose to build whatever they want. But sadly our world is not perfect and what language you choose will have a significant impact on your deployment cost, no matter what you which platform you decide to deploy on. Why you ask ??, I have two words for you Complied Size. Languages such as Javascript and Python has huge complied size compare to something written in Go, C++, etc, because program return in Javascript and Python include all the dependencies in their complied size. Higher size means higher storing cost which leads to higher deployment cost and deployment time. It is as simple as that. If you want to save as money as you possibly can, My recommendation is that you write your frontend in Next.js and for your backend use something like Go cause it has very low compile size as compare to something like Javascript while being easier to write and learn compare to something like Rust or C++. The Correct way to build a Docker Image If you are using docker images for deployment (p.s. you should), I learned that there are many optimization you do reduce the size of your docker image from (and I am not kidding) 1.7gb to like 100mb, and best the part it is that it can be achieved you just changing just a few lines of code in your dockerfile. You can imagine how much cost can you save from doing this in the long run. Here is a step by step for how you can reduce the size :- Choose a striped down base image, like python:3.10-alpine (60mb) instead of using python:3.10 (900mb) here is where you make the most significant reduction in size. Do a Multistage Build of docker images. Multistage builds allow you to keep the build dependencies and debug tools like GCC out of the final image which can significantly free up space. Make sure while building dependencies you use tags like --no-cache so there is not cache generated and even if it is generated make sure to delete in that step only. it can save up to like ~100mb Now I have an example of a bloated python docker image compare to an unbloated one and you can see the difference. This example created a docker image of 1.1gb FROM python:3.10 WORKDIR /app COPY . /app RUN pip install --no-cache-dir -r requirements.txt EXPOSE 8000 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] This example created a docker image of 160mb # ---------- Stage 1: Build depen

Introduction
This month I got my first bill for my google cloud platform. When I saw the bill, my first thought was "well, I am screwed, aren't I". It was like 6000 rupees ($70). I am a college student and there is no way in hell I can afford that.
So I did what any self respecting college student would do and decline all the payments and started fresh.
Armed with my prior experience, I started my crusade to find the cheapest and the most effective way to deploy my apps.
Which cloud platform to choose
Choosing the appropriate cloud platform, is the most important decision one can make, I mean they are the ones making the bills at the end of the day which you have to pay. So it is essential that every developer does his in depth research about these platforms, before making a decision.
Backend - I think Google Cloud Platform is the best for beginners. It is cheap, not that complicated to use, has a very generous free tier, and most importantly it asks before it charges your charges your credit card. Also while using it make sure that your storage and cloud run region are same and comes under the free tier of GCP, GCP charges extra for cross region transfer.
Frontend - Vercel is the best choice if your are using NEXT.js or any react app. One can deploy his/her frontend app easily in just 2 clicks with continuous deployment out of the box (any changes in main branch of github repo is automatically reflected there). Here is the fun part, you don't even need to enter your credit card details to get started, I know I haven't.
Why Seperate Frontend and Backend deployment
You must have noticed I choose different platforms for frontend and backend deployment. You might be wondering why do such a thing in the first place, isn't it better to have every thing on one place ??
The reason I do it because first it makes my work much more manageable, knowing that my frontend and backend seperated. But the more important reason is the specialized advantages that platform like Vercel provide for heavier frontend deployment (like static-site optimization, CDNs, caching) which platforms like Google Cloud Platform don't provide.
Google Cloud Platform, Heroku, AWS provide dynamic runtimes, scalability, database connection which are more tailored towards backend needs.
Having frontend and backend deployed seperately means that you don't have to worry about potential problems that might occur when you try to scale either.
What programming language to choose
I am of the belief that developers can choose whatever programming language to choose to build whatever they want. But sadly our world is not perfect and what language you choose will have a significant impact on your deployment cost, no matter what you which platform you decide to deploy on.
Why you ask ??, I have two words for you Complied Size.
Languages such as Javascript and Python has huge complied size compare to something written in Go, C++, etc, because program return in Javascript and Python include all the dependencies in their complied size.
Higher size means higher storing cost which leads to higher deployment cost and deployment time. It is as simple as that.
If you want to save as money as you possibly can, My recommendation is that you write your frontend in Next.js and for your backend use something like Go cause it has very low compile size as compare to something like Javascript while being easier to write and learn compare to something like Rust or C++.
The Correct way to build a Docker Image
If you are using docker images for deployment (p.s. you should), I learned that there are many optimization you do reduce the size of your docker image from (and I am not kidding) 1.7gb to like 100mb, and best the part it is that it can be achieved you just changing just a few lines of code in your dockerfile. You can imagine how much cost can you save from doing this in the long run.
Here is a step by step for how you can reduce the size :-
Choose a striped down base image, like python:3.10-alpine (60mb) instead of using python:3.10 (900mb) here is where you make the most significant reduction in size.
Do a Multistage Build of docker images. Multistage builds allow you to keep the build dependencies and debug tools like GCC out of the final image which can significantly free up space.
Make sure while building dependencies you use tags like --no-cache so there is not cache generated and even if it is generated make sure to delete in that step only. it can save up to like ~100mb
Now I have an example of a bloated python docker image compare to an unbloated one and you can see the difference.
This example created a docker image of 1.1gb
FROM python:3.10
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
This example created a docker image of 160mb
# ---------- Stage 1: Build dependencies ----------
FROM python:3.10-alpine AS builder
WORKDIR /app
# Add compiler tools for dependencies like numpy, psycopg2, etc.
RUN apk add --no-cache gcc musl-dev libffi-dev
COPY requirements.txt .
# Build all dependencies into .whl (wheel) files
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
# ---------- Stage 2: Final minimal image ----------
FROM python:3.10-alpine
WORKDIR /app
# Only runtime dependency
RUN apk add --no-cache libffi
# Copy built wheels from builder
COPY --from=builder /wheels /wheels
RUN pip install --no-cache-dir --no-index --find-links=/wheels /wheels/*
# Copy your application source code
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
Conclusion
Doing these steps can significantly reduce the cost of your deployment, but remember I have just scratched the surface of these kinds of optimization and I encourage to learn more tricks like these which and be used to save cost in deployment.
If you have any questions or feedback, I would love to take it and connect with you guys.