š What is Serverless? Serverless vs Monolith Explained with AWS Lambda


Learn how serverless architectures differ from traditional monolithsāand get hands-on with AWS Lambda in Node.js.
š Introduction
For decades, most web applications were built as monoliths: one big codebase running on servers you managed yourself.
Now, serverless is all the rageāwhere you write functions, upload them, and let the cloud handle everything else.
In this post, youāll discover:
What a monolithic architecture looks like
What serverless really means
Key differences between them
A practical AWS Lambda example in Node.js
When to choose serverless over monolith (and vice versa)
šļø 1. Monolith Architecture
Definition
A monolith combines all featuresāUI, business logic, data accessāinto a single deployable unit.
Typical Stack
One codebase (e.g., Express app)
One database (e.g., MongoDB)
Deployed on VMs or containers (EC2, Docker)
Pros & Cons
Pros | Cons |
Simple to develop & deploy | Hard to scale parts independently |
Easy local testing | Longer startup times |
One unified codebase | Large codebase ā complex changes |
āļø 2. What is Serverless?
Definition
Serverless means you write small, single-purpose functions, deploy them, and the provider auto-scales & manages the servers.
Characteristics
Event-driven: e.g., HTTP requests, queue messages
Pay-per-use: billed per invocation & duration
Auto-scaling: scales down to zero when idle
āļø 3. Monolith vs Serverless Comparison
Feature | Monolith | Serverless |
Deployment unit | Whole app | Individual functions |
Scaling | Scale entire app | Scale each function independently |
Cost | Pay for uptime (24/7 servers) | Pay only for executions |
Cold starts | Rare (always on) | Possible (first invoke latency) |
DevOps overhead | Manage servers, patching, autoscaling | Minimalāprovider handles infra |
Use case best fit | Complex, stateful apps | Microservices, event-driven tasks |
š ļø 4. Hands-On: Building an AWS Lambda Function in Node.js
Prerequisites
AWS CLI configured
Node.js (v14+)
SAM CLI (optional)
1. Initialize
mkdir lambda-hello
cd lambda-hello
npm init -y
npm install aws-sdk
2. Write Your Function (index.js
)
exports.handler = async (event) => {
console.log("Event:", event);
return {
statusCode: 200,
body: JSON.stringify({ message: "Hello from AWS Lambda!" })
};
};
3. Deploy with AWS CLI
zip -r function.zip .
aws lambda create-function \
--function-name helloServerless \
--runtime nodejs14.x \
--handler index.handler \
--zip-file fileb://function.zip \
--role arn:aws:iam::<YOUR_ACCOUNT_ID>:role/<YOUR_LAMBDA_ROLE>
4. Test It
aws lambda invoke \
--function-name helloServerless \
--payload '{}' response.json
cat response.json
šÆ 5. When to Use Serverless vs Monolith Choose Monolith when:
Choose Monolith when:
You need low-latency, always-on services
You have complex interdependent modules
You prefer simple deployments
Choose Serverless when:
You build event-driven microservices
You want zero-ops for scaling
You have unpredictable or spiky traffic
š Key Takeaways
Monolith = one big deployable, full control, but harder to scale per feature
Serverless = functions-as-a-service, auto-scale, pay-per-use, but watch out for cold starts
AWS Lambda makes it easy to get startedājust write your code, upload, and call
Subscribe to my newsletter
Read articles from amritadevs directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

amritadevs
amritadevs
Hey there šI'm a backend developer with 3+ years of experience working with Node.js, Redis, and scalable systems.I write about system design, breaking down complex architectures into simple, real-world examples with HLD, LLD, and working Node.js code.Follow along as I explore how to design systems like chat apps, URL shorteners, notification services, and more ā one post at a time š