CodePark/ questions / Compute: EC2, ECS, Fargate & EKS
START PRACTICINGPRACTICE
Backend question · Cloud & AWS › Compute: EC2, ECS, Fargate & EKS

You need to run a NestJS REST API on AWS. Compare EC2, ECS on EC2, ECS on Fargate, EKS and Lambda. Which would you pick for a small team, and why?

For a small team with a normal long-running HTTP API, pick ECS on Fargate most of the time. Lambda fits spiky or low traffic.

The options:

  • EC2 gives you raw virtual machines. You manage the OS, patching, process supervision and scaling yourself. You get maximum control, but also maximum work.
  • ECS on EC2 runs your containers on instances that you still manage. It can be cheaper when load is high and steady.
  • ECS on Fargate runs containers without servers. You set the CPU and memory for each task, and AWS runs it.
  • EKS is managed Kubernetes. It is worth it if you need the Kubernetes ecosystem or portability, but it adds real operational complexity.
  • Lambda runs a function for each request and scales to zero. But it has cold starts (a slow first call while a new instance starts), a 15-minute limit and connection-pooling problems.

Why Fargate? You deploy the Docker image you already build. There are no servers to manage. Autoscaling behind an ALB (Application Load Balancer) is simple.

  • EC2 gives full control, but you manage the OS and scaling.
  • ECS on EC2 runs containers on instances you manage, and it is cheaper at steady load.
  • Fargate runs containers without servers, and you pay for each task's CPU and memory.
  • EKS gives Kubernetes power and portability, but costs more operational work.
  • Lambda scales to zero, but has cold starts, a 15-minute limit and connection issues.