I have built a dynamic e-commerce sample website on GCP whose front end is hosted with Firebase hosting and written in node using lit and material. API back end is served using cloud run and written in Python using Django and Django REST framework. the database is stored in cloud SQL.
products used in this deployment
- cloud run- sever less and scales up and down automatically so that you focus on business logic and leave the infrastructure to Google.
- cloud build- service that will let you import the source code from the GitHub repository its hosted at.
- cloud SQL- relational database engine for the python app
- secrets manager- stores and manages secrets,API keys and database passwords
- cloud storage- stores static web files and container images for this project
- fire base- a development platform for building,monitoring ios android and web apps.
ways to build the dynamic web app
you can deploy this application in 2 ways you can use either the console or terraform.i attempted both and found that i liked the terraform route better.if you choose to use the console make sure to use a project that has billing enabled since this project doesn’t fall on the free tier also update your IAM permissions to avoid errors in the build.
APIs for the all services used need to be enabled for build to run successfully,don’t worry GCP will let you know which ones aren’t enabled already.
if you use terraform you will need to clone the GitHub repository that has the code and dependencies for this project to your cloud shell and editor.
after deploying i decided to update my application using terraform to add products and tweak a few lines of code on the client and also server side of the app. you cant do while using the console another reason why i like terraform better.
how the dynamic web app works
as i mentioned at the beginning of this article this application is made up of a frontend which gives you a GUI written using the lit framework and the backend that manages the storage,databases and other dependencies.
the front end uses Firebase hosting used widely with apps and websites across platforms.the backend on the other hand is made up the managed PostgreSQL database through cloud SQL.
Django uses database connection settings to connect the SQL database with the cloud storage bucket files while the API keys and passwords for the project are stored in the secrets manager for security.
cloud run is used to manage this containerized application code and images in this project.settings have been set to allow unauthenticated access since its managing the code of a public eCommerce site.cloud run has been set to scale to a max of 3 instances and CPU is only allocated during request processing saving cost and reducing idle runs.
cloud storage stores all the static files and container images used by cloud run in the project.
2 health checks have also been enabled for the project and there are no Eventarc triggers or integrations.
project cost and lessons
according to the GCP pricing calculator, the project costs a minimum of $84 a month to run but since I have google cloud credits I have decided to let it run and monitor it to understand it better no harm in that. Through this project, I have also found that I enjoy working with the frontend better as compared to the backend.
follow this post for updates on this application through time.