My Journey to a Web App Platform | EP.3 Infrastructure

Pongsatorn Manusopit
4 min readAug 15, 2024

--

After developing all the features for MVP1, it’s time to deploy everything to the production environment.

Backend

For our first production launch, it needs to be cost-saving because we don’t have any income yet. The cloud provider I chose is AWS because I am familiar with it. Normally, I prefer to deploy on Kubernetes (K8s), but for AWS EKS, the control plane alone costs $0.10 per hour (around $72 per month) without including the compute nodes.

First, I thought about deploying it manually on AWS EC2 with a purchase Reserved Instances to reduce costs. However, I decided to test AWS ECS because they only charge for EC2 compute costs and no additional ECS costs.

This is what I ended up with: AWS ECS with EC2 spot instances without a load balancer. Normally, AWS ECS would use AWS Auto Scaling Groups (ASG) to provision EC2 instances and AWS Elastic Load Balancer (ELB) to distribute the load to EC2 instances. However, ELB costs $0.0252 per hour (around $18 per month), so I found ways to use ECS without ELB.

I set ASG to attach public IPv4 addresses to EC2 instances, then forward traffic directly to these EC2 instances. This approach has one major drawback: when EC2 spot instances are interrupted or redeployed on other EC2 instances, the IP addresses will change. This means you have to update the IP addresses every time this happens. However, this is acceptable for me because I have AWS ECS to manage the service for me. Additionally, by using EC2 spot instances, I benefit from much lower costs compared to on-demand instances.

No load balance?

For my initial needs, the traffic should not be high, so I will stick with a single instance without any auto scaling. There will be changes to infrastructure in the future when there is more traffic and income.

Ec2 instance types

I chose the T4g family instances because they are ARM-based. ARM instances tend to have a lower chance of being interrupted and generally offer lower pricing. This choice helps in optimizing cost efficiency while ensuring a more stable deployment environment.

Database

For the database, I used TiDB Serverless Cloud because it has a free tier that should be enough for my initial needs. The free tier offers enough capacity for small-scale applications and allows me to scale when necessary without worrying about immediate costs.

Final Diagram

Diagram for backend

When EC2 IP changed, I need to update CloudFront origin to new IP

Frontend

For the frontend, I hosted it on Vercel. Vercel offers great performance and an easy-to-use platform for static site hosting and serverless functions. It’s a great solution for my needs. Vercel integrates seamlessly with my GitLab repository, so every time I push a new commit, the changes are automatically deployed. This makes the development process smooth and efficient, allowing me to focus more on coding rather than managing deployments.

Worker

For the worker processes, I hosted them on my personal PC because they require a lot of compute power, especially when rendering Blender scenes. My personal PC has the necessary resources and GPU power to handle these rendering tasks efficiently, which helps in cutting down additional cloud costs. It also allows me to maintain direct control over the compute-heavy operations, ensuring they run smoothly and quickly.

Cost Breakdown

Here’s a quick breakdown of the costs:

  • AWS ECS with EC2 Spot Instances: Spot instances can be up to 90% cheaper than on-demand instances. I chose t4g.small so the spot instance cost is approximately $5.9 for a month (730 hours).
  • AWS Auto Scaling Group: No additional cost, managed under the EC2 costs.
  • Elastic Load Balancer (ELB): Not used, saving $18 per month.
  • Public IPv4 Addresses: $3.6 for a month.
  • TiDB Serverless Cloud: Utilizing the free tier, resulting in $0 cost initially.
  • Vercel Hosting: Vercel has a generous free tier that suits small, growing applications. Assuming sticking to this free tier, the cost is $0.
  • Personal PC for Worker Processes: No additional cloud cost, just personal electricity and internet bills, which vary by location.

Adding it all up, the monthly cloud infrastructure cost is approximately $9.5 with significant savings from spot instances and the free-tier offerings of Vercel.

--

--

No responses yet