Cloud Infrastructure of my Web App
Over the past few months I’ve been building a web app to get a better understanding of web development since I come from a game development background.
I had started out by toying with a Golang server, just serving raw HTML, CSS, JS and JSON payloads, but soon realized there had to be a better way of handling my frontend logic.
Eventually I added a NextJS app to serve as a frontend, separating the backend API from the client code. At the same time I also connected my backend to a Redis Cache for session management and to a Postgres DB to read and write relevant data.
I had a decent setup for local development and a docker setup with containers, but I also wanted to deploy this application “for real”, be it for the learning experience or even potential launch to the public one day.
I could have simply deployed with my docker-compose
as is in a VPS but I wanted to get a basic grasp on some of these buzzwords I had heard and read so much about (but had no idea what they were in practical terms). AWS, GCP, EC2, App Engine, Serverless, Kubernetes Engine, Lambda Functions and so many others.
I explored some platforms like AWS, Heroku, Fly.io, Vercel, GCP, Azure and more. Ultimately I decided to go with GCP. Although it would definitely be more complicated than a lightweight solution like Heroku or Vercel, I wanted to go deep and learn as much as I could in one of the big three (AWS, Azure, GCP), since they would probably be the most used in a corporate setting and had the highest ceiling with their infinite amount of different services.
Since I was really enjoying my time with Golang I decided to go with GCP (Golang was designed at Google), because why not. Not a lot of thought went into this decision to be fair. I also had friends with experience in GCP, so it was comforting to know I could fall back on them for direction and questions.
After playing around for a bit, this is how my cloud infrastructure looked:
I investigated the 4 main ways to deploy an app on GCP, namely:
- Compute Engine (Essentially a VPS, I would have to handle everything)
- App Engine (Serverless but seemed a bit rigid and impractical)
- Kubernetes Engine (Container based, but having to also learn Kubernetes would be over the scope)
- Cloud Run (Serverless, Container based, Modern - not necessairly a pro though)
There were a few others, but for my use case, these were the main ones. Since I was using Docker containers, KE or CR would probably make the most sense.
However, learning Kubernetes on top of back- & frontend development and cloud computing as a whole, seemed a bit overkill and would probably burn me out. So I decided to go with Cloud Run. Cloud Run seemed like an easier service since it managed A LOT of the complexity on its own, letting me focus more on the business logic of my API and frontend. KE would offer more flexibily but would require a much more complex setup.
I deployed 2 services, one for the Next App and another for the Golang API. At first, I did the deployment process manually but soon integrated them into a CI/CD pipeline for efortless deployement.
I put a load balancer with the proper domain mappings before these 2 services to access them through a domain I purchased.
I still needed to host my Redis and Postgres somewhere. Had I gone with Compute Engine for the back- and frontend apps, I could have simply spun up a Postgres DB and Redis Cache on the VM. Even using Cloud Run for the two apps, I could have just used Compute Engine regardless.
However, having experienced the serverless nature of Cloud Run, I wanted something similar for Redis and Postgres. GCP offers managed services for these (Memorystore for Redis and CloudSQL for Postgres), but they were prohibitively expensive!
I searched around and found 2 external solutions. Supabase for Postgres and Upstash for Redis.
I had heard of Supabase beforehand, but I had no idea what the use case for a service like this would be. I had played around with MySQL in university, but when it came to actually deploying an app that required a DB, I really had no idea what that would look like (mostly because DBs are not so relevant in game dev). Even then I always assumed one could easily just use something on AWS or GCP. But after having experienced the ease of Cloud Run, it was hard to justify not using Supabase and Upstash. And both of these had very generous free plans which I could take advantage of!
I imagine both of these just leverage existing cloud providers such as GCP and AWS and use their non-managed solutions like Compute Engine or EC2 and “write a bunch of code” to make an easy to use interface that lets me create databases at will that will scale and are fault-tolerant.
And that covers all the platforms and services used. This web app is very simple in terms of requirements and is not really under a lot of stress in terms of users (0), although I believe it would scale reasonably due to the way its structured.
I learned A LOT about GCP and a bunch of its services (IAM, IAP, WIF, Artifact Registry, Cloud Run, Cloud Build, Load Balancers, VPC, VPN, and more), how to navigate them in the console and to use the gcloud cli.