Introduction
When I started learning AWS, I thought "Serverless" meant there were literally no servers. I imagined code floating in the clouds like magic. 🪄
As I dug deeper into services like EC2, Lambda, and Fargate, I realized that "Serverless" is just a buzzword for "Someone else manages the servers for you."
But how do you choose? Should you manage it yourself (Server-based) or let AWS handle it (Serverless)? To understand this, I like to use the Pizza Analogy.🍕
1. The "Do-It-Yourself" Approach: Amazon EC2
Think of Amazon EC2 (Elastic Compute Cloud) like baking a pizza at home.
- You buy the ingredients (OS, CPU, RAM).
- You pre-heat the oven (Provisioning).
- You bake the pizza (Running the app). The Catch: You have to clean the kitchen afterwards. If you aren't using the oven, you still paid for it.
In Tech Terms: EC2 gives you a Virtual Machine. You have total control. You can install whatever you want, tweak the operating system, and configure the security.
- Pros: Complete control. Great for long-running applications or legacy software.
- Cons: You pay for the server 24/7, even if no one visits your website. You are responsible for security patches.
2. The "Buy a Slice" Approach: AWS Lambda
Think of AWS Lambda like walking into a pizza shop and buying one slice.
- You don't care what oven they used.
- You don't care who the chef is.
- You just pay for the slice, eat it, and leave.
In Tech Terms: This is true Serverless. You upload your code (a function), and AWS runs it only when needed.
- Pros: You pay $0 when no one is using it. It scales instantly (from 1 user to 1 million).
- Cons: "Cold Starts" (it takes a split second to wake up). Not good for long tasks (max 15 minutes).
3. The Middle Ground: Fargate (Containers)
This is where I used to get confused. I kept hearing about ECS and EKS.
- ECS/EKS are just "Managers." They organize your containers (like Docker). But where do those containers run? You have two choices:
- EC2 Mode: You run the containers on servers you manage. (Server-based).
- Fargate Mode: You tell AWS "Here is my container, just run it." (Serverless).
Think of Fargate like ordering pizza for delivery. You get the whole pizza (custom container), but you don't have to worry about the oven or the kitchen. AWS manages the underlying infrastructure, and you just focus on the app.
Which one should you choose?
As I am building my own projects, here is my rule of thumb:
- Start with Lambda if you are building a simple API or a background task. It’s cheap and easy.
- Use Fargate if you have a Docker container and want it to run without managing servers.
- Use EC2 only if you need full control over the OS or have a very steady workload where you can reserve capacity to save money.
Conclusion
There is no "winner" here. Real cloud architects use all of them together. You might use EC2 to host a database, Fargate to run your backend API, and Lambda to process image uploads.
I’m still exploring these services, so if you have a favorite use case for Lambda or Fargate, let me know in the comments!
Top comments (0)