Codementor Events

How and why I built a scalable Laravel application on AWS ECS Fargate

Published May 13, 2020

About me

An experienced Tech Director with passion for Ecommerce, DevOps and cloud infrastructure

The problem I wanted to solve

Scalable automated application architecture

What is A scalable Laravel application on AWS Fargate?

I built a Laravel application running on NGINX, PHPFPM on a load-balanced, auto-scaling AWS ECS and Fargate architecture connected to an RDS instance.

I also setup a rolling deployment pipeline on buddy.works connected to bitbucket to automatically deploy build docker images and deploy code to AWS ECS.

All tools are on free tier or minimal cost making this a reliable, cost-effective setup for prototyping.

Tech stack

Laravel, PHP, MySQL, NGINX, PHPFPM, Docker, AWS ECS, AWS Fargate, AWS ELB

The process of building A scalable Laravel application on AWS Fargate

I start by coding Laravel application on local machine and push to a bitbucket repository.

Then setup a Buddy.works pipeline to pull code from Bitbucket, package into Docker images and push to AWS Elastic Container Registry (ECR).

The pipeline also spins up a new task in an Elastic Container Service (ECS) cluster. The cluster is load-balanced and auto-scaled, which enables the application to be scaled when production-ready.

Challenges I faced

Configuring multiple components requiring knowledge of several computer languages and networking protocols.

Key learnings

An automated DevOps deployment pipeline to a scaled cloud infrastructure is very useful to small agile teams with little or no infrastructure experience. Everything downstream is taken care of, so you only have to be concerned mostly with coding.

Once production-ready, it is also easy to spin up auto-scaled versions without any significant infrastructure changes.

Tips and advice

Containerize! Modularize!

Final thoughts and next steps

Using the same approach, it is now possible to setup any tech stack using the many publicly available docker images provided by most major technology providers.

This tech stack is low-cost, scalable and using best-in-class AWS infratructure. In my opinion, this is the best way to prototype your next cloud-enabled application.

Discover and read more posts from Bernard Tai
get started
post commentsBe the first to share your opinion
Carl-Erik Kopseng
3 years ago

Three things that come to mind.

  1. AWS Fargate: this seems like a great way to setup dev, staging and production environments without spending a lot of $$$, given that they cost nothing when not in use. But what are the downsides? Say you have a Laravel docker container that has not seen any traffic in ages (like in your staging env at night time), how long does it take to spin up when HTTP traffic comes in?

  2. Proxying: Why use nginx if you can use AWS own service for reverse proxying?

  3. Local development vs cloud. Do you spin up a local Vagrant VM or docker images or what when doing local development? Is nginx used locally? The difference between local and production env seems like an issue.

Show more replies