
No Comments Yet
Be the first to share your thoughts and start the conversation.
Be the first to share your thoughts and start the conversation.
Imagine you want to run a restaurant, but instead of owning and maintaining a massive kitchen, you:
That’s exactly how serverless backends work in the tech world. You write code, and Cloud providers like AWS, Google Cloud, Azure, or Vercel handle everything else for you.
While the term “serverless” might sound like there are no servers involved, servers do exist—they are just fully managed by a cloud provider, abstracted away from you, developers. But why this abstraction?
This abstraction allows you to focus on writing application logic while cloud providers handle infrastructure, scaling, and maintenance of your backend.
Let’s say you’re developing an API for a food delivery app or anything that comes to your mind.
With Traditional Backend
You deploy your backend (e.g., a Node.js Express.js API app) on a Heroku dyno or an AWS EC2 instance. In this case,
While you get the whole freedom and your own server, you’ve to face some challenges,
If you know enough about this and the domain of DevOps and rest related, you shouldn’t feel these as challenges but rather a piece of cake.
With Serverless Backend
You write an API function that handles requests like, say, creating an order. You deploy this as a serverless function (more on that later).
I hope now you have the idea of how a Serverless backend is actually Serverless and is different from a Traditional backend.
A serverless backend is a collection of different serverless functions that work together to form an application's backend logic.
You write it, deploy it, and the cloud provider takes care of hosting, scaling, and executing it.
But what does a Serverless Function Look like?
It’s different for different providers.
If you’ve used Next.js to do some backend, you’ve already used Serverless functions. Congrats.
Below are examples of serverless functions for famous different providers:
AWS Lambda
It’s the most popular serverless platform. And you can write functions in various languages like Python, Node.js, or Go
A simple Node.js serverless function,
export const handler = async (event, context) => {
console.log("EVENT: \n" + JSON.stringify(event, null, 2));
return context.logStreamName;
};
Google Cloud Functions
It supports writing functions for JavaScript, Python, Go, and more. Also it integrates well with other Google Cloud services.
A basic HTTP function,
exports.helloWorld = (req, res) => {
res.send("Hello, World");
};
Azure Functions
It integrates seamlessly with Microsoft’s ecosystem and similar support languages, such as C#, Java, Python, JavaScript, etc.
A basic Azure function,
app.http("helloWorld1", {
methods: ["POST", "GET"],
handler: async (request, context) => {
context.log("Http function was triggered.");
return { body: "Hello, world!" };
},
});
Vercel Functions
And that’s everyone’s favorite. Vercel specializes in serverless functions for frontend (through Next.js) and edge deployment, making it greater for web applications
A Next.js Route handler
export const dynamic = "force-dynamic"; // static by default, unless reading the request
export function GET(request) {
return new Response(`Hello from ${process.env.VERCEL_REGION}`);
}
That’s it for now. More so, all of them look similar. It’s basically: Learn Concept and Do Anything play. If you learn to build serverless backends using, say, Vercel, you won’t have that much of a problem with others.
I wouldn’t say so. Never ever.
Depending on my knowledge so far, below are the perfect candidates for serverless backend:
Startups/Small Teams
Serverless allows you to focus on building and iterating on the product instead of dealing with infrastructure, which is a perfect fit for small teams or startups.
In this case, you don’t need to worry about scaling your servers as your user base grows, and you can quickly deploy without upfront hardware costs.
Especially if you’re a student/developer with some SaaS plan, I would suggest going with this. Just get that prototype done first and then overcomplicate things if you would like.
Businesses with Unpredictable Traffic
If your website or service has fluctuations in traffic (e.g., high traffic during sales or special events), then serverless is a perfect fit, as it can automatically scale to meet demand and handle a surge of users without requiring you to invest in and manage excess server capacity
Okay then,
While serverless computing is efficient and cost-effective for many scenarios, it’s not a one-size-fits-all-solution.
Below are the cases where I think you better go with traditional backends:
An application requiring constant performance
If you work or have an application like a trading platform, real-time gaming server, or even live streaming where applications require continuous availability and minimal latency, then the traditional backend is the way to go.
Serverless in these scenarios may introduce some delay, especially if the function hasn’t been invoked recently. That’s its drawback, famously known as a “cold start”.
Complex, Long Running Processes
Serverless is generally better for short-lived tasks.
Complex, long-running processes like training machine learning models or rendering videos may not be a good fit because serverless functions are designed for fast, short executions.
Organizations with Specific Compliance Needs
Industries like Healthcare or finance have a strict regulations around data handling, including where data is stored and processed.
Since serverless functions are typically managed by cloud providers, you may not have full control over the physical servers or the location where your data is processed. This could be a barrier for organizations with strict data residency or security compliance requirements.
Got it?
By now, you should be able to decide what to use for your next portfolio project, that SaaS app idea, or the company project you'll be working on.
Remember, serverless isn’t a universal solution. It’s a tool, and like any tool, it’s used in the right context.