Serverless Backend: A New Era for Developers
Serverless Backend: A New Era for Developers
Serverless Backend: A New Era for Developers

Serverless Backend: A New Era for Developers

By:

Suryakant Das

26 May 2025

As Developers, we’ve all been in this situation, using node index.js to start an Express server on port 3000. This method has proved useful for some time, but making it work in production takes a lot of effort.

In traditional deployment, you select a cloud provider such as AWS, GCP, Azure or Cloudflare, rent virtual machines and start to deal with operational problems like:

  • Using Auto Scaling Groups or Kubernetes to manage scaling in a complex way

  • Charging for idle resources when there is little traffic

  • Regular watch over server conditions and maintenance

  • Need to manually deploy and restart after changing the code

  • Organizing what to do during unexpected downtime and failures

These problems take our focus away from the main thing we enjoy, creating code that solves real issues. Is there a way we can do better?

Serverless backend

Comparing Traditional vs. Serverless Deployment

Traditional Node+Express Deployment

Write code Push to GitHub SSH into VM Git pull Restart PM2 Restart application

Serverless Cloudflare Workers and Hono Deployment

Write code npm run deploy Done

The Serverless Revolution

The cloud provider handles the management and provisioning of servers for this kind of deployment, referred to as "serverless." Even though it's called serverless, there are still servers involved. As a result, developers and operators do not have to think about the servers.

Why Serverless is Better Than Traditional Hosting:

  • Build applications using code rather than setting up infrastructure yourself

  • You are charged only for running code (typically very fast)

  • Managing one user or one million is as simple as a flip of a switch without any changes needed.

  • It handles everything for you, no need to update, patch or monitor the server

  • Availability zones are used by default to host your application.

Essentially, in serverless development, you create your API routes, deploy them and the server will handle the rest as the traffic increases.

Setting Up a Modern Serverless Application

A well-structured serverless application usually consists of these items:

Layer

Purpose

Example Services

Frontend

Static site hosting

Vercel, Netlify, Cloudflare Pages

Backend

API functions

AWS Lambda, Cloudflare Workers, GCP Functions

Database

Data persistence

NeonDB, PlanetScale, DynamoDB

Popular Serverless Providers and How They Operate

You have several good choices when selecting a serverless platform:

1. AWS Lambda

AWS Lambda
  • What it is: The first major serverless platform, created by Amazon

  • What's good about it: Works well with other Amazon services like databases and file storage

  • Languages you can use: JavaScript, Python, Java, and many others

  • Best for: Projects already using other AWS services

(AWS Lambda)

2. Google Cloud Functions

Google cloud functions
  • What it is: Google's serverless platform

  • What's good about it: Easy to use with other Google Cloud tools

  • Languages you can use: JavaScript, Python, Go, and Java

  • Best for: Projects that use other Google services

(Google Cloud Functions)

3. Cloudflare Workers

cloudflare workers
  • What it is: A serverless platform that runs code close to users

  • What's good about it: Super fast because it runs in 275+ locations worldwide

  • How it's different: Uses a different technology than the others (V8 isolates)

  • Best for: Projects where speed is important

(Cloudflare Workers)

When Should You Use Serverless?

Serverless isn’t the best tool for every job, but it’s very useful in these cases:

  • When you want to launch quickly
    You don’t need to handle server setup when using Serverless; you can just work on your code. Just write your code, deploy it, and it works!

  • When you're not sure how many users you'll have
    Serverless can automatically deal with increased traffic on your website. No matter how many users you have, the system automatically adjusts for you.

  • When you want to save money on low-traffic apps
    You only have to pay for serverless use when someone uses your app. No visitors means no charges!

Serverless technology is also suited for:

  • Handling events (like when someone uploads a file)

  • Building APIs (the code that apps use to talk to servers)

  • Making small, targeted services

  • Executing tasks at set times

How Cloudflare Workers is Different

How Cloudfkare Workers work

Cloudflare Workers is special in how it runs your code:

Different Technology: Isolates vs. Containers

Most serverless platforms such as AWS Lambda, make use of containers that work like little computers.

  • It takes 300ms-1000ms for a program to start (which is quite slow).

  • Use as much computer memory as possible

  • Not good enough to handle sudden increases in traffic

The technology Cloudflare Workers relies on, called V8 isolates, is the same one used by Chrome to keep tabs apart.

  • The startup time is less than 1ms.

  • Require little space in the system

  • Manage increased traffic without problems

As a result, Cloudflare Workers can be up and running in just one-tenth the time needed by other serverless platforms.

Different Runtime: Not Node.js

Cloudflare Workers doesn’t rely on Node.js which is different from most other platforms. This means:

  • Some features you may have used in Node.js aren’t present

  • You can't reach the files directly.

  • You can’t use some common Node.js packages

  • It measures the use of CPU instead of total running time

If you’ve used Node.js before, this might take a little getting used to.

Problems with Using Raw Cloudflare Workers

Working with Cloudflare Workers on your own can be quite tricky.

  • It gets harder to organize routes as your app gets bigger.

  • There aren’t any automatic systems for handling common activities

  • Responding to requests and sending responses takes much more code than you would think.

Because of this, many developers turn to frameworks like Hono which offer the same benefits as Express.js and solve these issues for you.

Hono: Express-like Development for Serverless

Hono

Hono was created with Express.js users in mind and so it should feel very comfortable to you. Thanks to its size (only ~13KB), this framework now introduces the easy routing and middleware capabilities we love to serverless projects.

(Hono)

Why Hono is Special

  • Familiar API: The app.get(), app.post() functions are used for routing.

  • Fast response: Made for edge networks

  • Built-in middleware: Body parsing, CORS, JWT authentication and additional middleware are included.

  • Platform agnostic: Runs the same on Workers, Lambda, Bun and Deno

You can write code in Hono like this:

app.get('/api/users', (c) => {
  return c.json({ users: [...] });
});

It simply functions, without making any changes, on any serverless platform.

Building a Complete Todo API with Hono

We’ll put the theory into action by building a Todo API that is ready for production with the modern serverless stack. This example shows you how to develop and deploy your application.

1. Making a New Hono Project

With the CLI, you can quickly launch a new Hono project.

npm create hono

At setup, you’ll:

  • Decide on a name for your project’s directory.

  • Choose the Cloudflare Workers template.

  • Verify that dependencies have been installed

  • Pick the package manager that works best for you (npm, yarn or pnpm)

2. Setting Up Local Development

Hono gives you a local development experience that is very similar to Express.

npm run dev

After that, a local development server will be set up to help you test your APIs before they are deployed to the production environment.

3. Adding Database Connectivity with Prisma

We’ll rely on Prisma and NeonDB for the database part of our project.

npm install @prisma/client
npm install prisma --save-dev
npm install @prisma/extension-accelerate

4. Understanding Serverless Database Connections

A key idea in serverless technology is managing how connections are handled. Connection pools can’t be used effectively in serverless environments.

  • Every time a function is invoked, it creates a new connection pool

  • Having idle connections results in wasted resources and makes things more expensive

  • It takes longer for the machine to boot up when it’s a cold start because of the extra time needed to start the connection.

The Serverless Database Challenge
Serverless database connection

There are distinct issues that arise when trying to connect serverless environments to databases.

  • Since workers might run in many edge locations at once, they could use up the database connections very fast.

  • Since the Cloudflare Workers runtime doesn’t use Node.js, many database libraries, including Prisma, cannot be used.

  • The time it takes to make a traditional database connection slows down the first use of an app which impacts the user experience.

This is the reason @prisma/extension-accelerate is needed. It provides:

  • Improved connection pooling for serverless functions with HTTP.

  • Decreased time for the server to become active

  • Saving resources and money

  • Can be used with edge runtimes, including Cloudflare Workers

Make sure to use the special NeonDB connection pooling URL in your .env file.

DATABASE_URL="postgresql://username:password@neondb.io/dbname?connection_limit=1"


npx prisma init

Create Your Schema in prisma/schema.prisma

model Todo {
  id          Int      @id @default(autoincrement())
  title       String
  description String?
  userId      Int
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

Make a Prisma Client.

npx prisma generate

5. Using the Todo API Endpoints

Now, we’ll create a full RESTful Todo API using Hono and Prisma.

import { Hono } from "hono";
const app = new Hono();
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

// Get single Todo
app.get("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoDetails = await todo.findUnique({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Todo details", todoDetails });
});

// Get all Todos
app.get("/api/v1/todo", async (c) => {
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const allTodo = await todo.findMany();
  return c.json({ message: "All Todos", allTodo });
});

// Create a Todo
app.post("/api/v1/todo", async (c) => {
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoData = await todo.create({
    data: {
      title: body.title,
      description: body.description,
      userId: 1,
    },
  });

  return c.json({ message: "Created a Todo", todoData });
});

// Delete a Todo
app.delete("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const data = await todo.delete({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Deleted a Todo", data });
});

// Patch/Update a Todo
app.patch("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const updatedTodo = await todo.update({
    where: { id: parseInt(id) },
    data: body,
  });

  return c.json({ message: "Updated a Todo", updatedTodo });
});

export default app;

With the code, we have created a full CRUD API for handling todos that:

  • Generates additional tasks to do

  • Fetches both single todos and collections of todos

  • Brings up open todos

  • Removes todos after they are completed

Getting Your Site Online

You can deploy your Hono app to Cloudflare Workers with only one command.

npm run deploy

It only takes moments for your API to go live and start handling requests from everywhere. You do not need to set up servers, configure scaling or look after your infrastructure.

Conclusion

Switching from traditional Node.js + Express hosting to a modern serverless setup with Cloudflare Workers and Hono streamlines development, reduces costs, and eliminates infrastructure headaches. By leveraging serverless architecture, edge deployment, and database solutions like NeonDB with Prisma, developers can build fast, scalable, and production-ready APIs with minimal effort. You can use serverless to focus on what you love, writing great code and delivering powerful web applications.


Frequently Asked Questions

Q. What is serverless deployment and how does it benefit developers?

A. Serverless deployment allows developers to run code without managing servers. Cloud providers like AWS Lambda and Cloudflare Workers automatically handle infrastructure, scaling, and maintenance. This approach reduces operational overhead, lowers costs, and enables faster development cycles.

Q. How do Cloudflare Workers differ from AWS Lambda?

A. Cloudflare Workers run on V8 isolates, offering sub-millisecond cold starts and global edge deployment, leading to lower latency. In contrast, AWS Lambda uses containers, which can result in higher cold start times and regional deployment. Cloudflare Workers are ideal for performance-critical, globally distributed applications.

Q. What is the Hono framework and why is it suitable for serverless applications?

A. Hono is a lightweight, high-performance web framework built on Web Standards. It supports multiple JavaScript runtimes, including Cloudflare Workers, Deno, and Bun. With an Express-like API, Hono simplifies serverless application development, offering fast routing and built-in middleware support.

As Developers, we’ve all been in this situation, using node index.js to start an Express server on port 3000. This method has proved useful for some time, but making it work in production takes a lot of effort.

In traditional deployment, you select a cloud provider such as AWS, GCP, Azure or Cloudflare, rent virtual machines and start to deal with operational problems like:

  • Using Auto Scaling Groups or Kubernetes to manage scaling in a complex way

  • Charging for idle resources when there is little traffic

  • Regular watch over server conditions and maintenance

  • Need to manually deploy and restart after changing the code

  • Organizing what to do during unexpected downtime and failures

These problems take our focus away from the main thing we enjoy, creating code that solves real issues. Is there a way we can do better?

Serverless backend

Comparing Traditional vs. Serverless Deployment

Traditional Node+Express Deployment

Write code Push to GitHub SSH into VM Git pull Restart PM2 Restart application

Serverless Cloudflare Workers and Hono Deployment

Write code npm run deploy Done

The Serverless Revolution

The cloud provider handles the management and provisioning of servers for this kind of deployment, referred to as "serverless." Even though it's called serverless, there are still servers involved. As a result, developers and operators do not have to think about the servers.

Why Serverless is Better Than Traditional Hosting:

  • Build applications using code rather than setting up infrastructure yourself

  • You are charged only for running code (typically very fast)

  • Managing one user or one million is as simple as a flip of a switch without any changes needed.

  • It handles everything for you, no need to update, patch or monitor the server

  • Availability zones are used by default to host your application.

Essentially, in serverless development, you create your API routes, deploy them and the server will handle the rest as the traffic increases.

Setting Up a Modern Serverless Application

A well-structured serverless application usually consists of these items:

Layer

Purpose

Example Services

Frontend

Static site hosting

Vercel, Netlify, Cloudflare Pages

Backend

API functions

AWS Lambda, Cloudflare Workers, GCP Functions

Database

Data persistence

NeonDB, PlanetScale, DynamoDB

Popular Serverless Providers and How They Operate

You have several good choices when selecting a serverless platform:

1. AWS Lambda

AWS Lambda
  • What it is: The first major serverless platform, created by Amazon

  • What's good about it: Works well with other Amazon services like databases and file storage

  • Languages you can use: JavaScript, Python, Java, and many others

  • Best for: Projects already using other AWS services

(AWS Lambda)

2. Google Cloud Functions

Google cloud functions
  • What it is: Google's serverless platform

  • What's good about it: Easy to use with other Google Cloud tools

  • Languages you can use: JavaScript, Python, Go, and Java

  • Best for: Projects that use other Google services

(Google Cloud Functions)

3. Cloudflare Workers

cloudflare workers
  • What it is: A serverless platform that runs code close to users

  • What's good about it: Super fast because it runs in 275+ locations worldwide

  • How it's different: Uses a different technology than the others (V8 isolates)

  • Best for: Projects where speed is important

(Cloudflare Workers)

When Should You Use Serverless?

Serverless isn’t the best tool for every job, but it’s very useful in these cases:

  • When you want to launch quickly
    You don’t need to handle server setup when using Serverless; you can just work on your code. Just write your code, deploy it, and it works!

  • When you're not sure how many users you'll have
    Serverless can automatically deal with increased traffic on your website. No matter how many users you have, the system automatically adjusts for you.

  • When you want to save money on low-traffic apps
    You only have to pay for serverless use when someone uses your app. No visitors means no charges!

Serverless technology is also suited for:

  • Handling events (like when someone uploads a file)

  • Building APIs (the code that apps use to talk to servers)

  • Making small, targeted services

  • Executing tasks at set times

How Cloudflare Workers is Different

How Cloudfkare Workers work

Cloudflare Workers is special in how it runs your code:

Different Technology: Isolates vs. Containers

Most serverless platforms such as AWS Lambda, make use of containers that work like little computers.

  • It takes 300ms-1000ms for a program to start (which is quite slow).

  • Use as much computer memory as possible

  • Not good enough to handle sudden increases in traffic

The technology Cloudflare Workers relies on, called V8 isolates, is the same one used by Chrome to keep tabs apart.

  • The startup time is less than 1ms.

  • Require little space in the system

  • Manage increased traffic without problems

As a result, Cloudflare Workers can be up and running in just one-tenth the time needed by other serverless platforms.

Different Runtime: Not Node.js

Cloudflare Workers doesn’t rely on Node.js which is different from most other platforms. This means:

  • Some features you may have used in Node.js aren’t present

  • You can't reach the files directly.

  • You can’t use some common Node.js packages

  • It measures the use of CPU instead of total running time

If you’ve used Node.js before, this might take a little getting used to.

Problems with Using Raw Cloudflare Workers

Working with Cloudflare Workers on your own can be quite tricky.

  • It gets harder to organize routes as your app gets bigger.

  • There aren’t any automatic systems for handling common activities

  • Responding to requests and sending responses takes much more code than you would think.

Because of this, many developers turn to frameworks like Hono which offer the same benefits as Express.js and solve these issues for you.

Hono: Express-like Development for Serverless

Hono

Hono was created with Express.js users in mind and so it should feel very comfortable to you. Thanks to its size (only ~13KB), this framework now introduces the easy routing and middleware capabilities we love to serverless projects.

(Hono)

Why Hono is Special

  • Familiar API: The app.get(), app.post() functions are used for routing.

  • Fast response: Made for edge networks

  • Built-in middleware: Body parsing, CORS, JWT authentication and additional middleware are included.

  • Platform agnostic: Runs the same on Workers, Lambda, Bun and Deno

You can write code in Hono like this:

app.get('/api/users', (c) => {
  return c.json({ users: [...] });
});

It simply functions, without making any changes, on any serverless platform.

Building a Complete Todo API with Hono

We’ll put the theory into action by building a Todo API that is ready for production with the modern serverless stack. This example shows you how to develop and deploy your application.

1. Making a New Hono Project

With the CLI, you can quickly launch a new Hono project.

npm create hono

At setup, you’ll:

  • Decide on a name for your project’s directory.

  • Choose the Cloudflare Workers template.

  • Verify that dependencies have been installed

  • Pick the package manager that works best for you (npm, yarn or pnpm)

2. Setting Up Local Development

Hono gives you a local development experience that is very similar to Express.

npm run dev

After that, a local development server will be set up to help you test your APIs before they are deployed to the production environment.

3. Adding Database Connectivity with Prisma

We’ll rely on Prisma and NeonDB for the database part of our project.

npm install @prisma/client
npm install prisma --save-dev
npm install @prisma/extension-accelerate

4. Understanding Serverless Database Connections

A key idea in serverless technology is managing how connections are handled. Connection pools can’t be used effectively in serverless environments.

  • Every time a function is invoked, it creates a new connection pool

  • Having idle connections results in wasted resources and makes things more expensive

  • It takes longer for the machine to boot up when it’s a cold start because of the extra time needed to start the connection.

The Serverless Database Challenge
Serverless database connection

There are distinct issues that arise when trying to connect serverless environments to databases.

  • Since workers might run in many edge locations at once, they could use up the database connections very fast.

  • Since the Cloudflare Workers runtime doesn’t use Node.js, many database libraries, including Prisma, cannot be used.

  • The time it takes to make a traditional database connection slows down the first use of an app which impacts the user experience.

This is the reason @prisma/extension-accelerate is needed. It provides:

  • Improved connection pooling for serverless functions with HTTP.

  • Decreased time for the server to become active

  • Saving resources and money

  • Can be used with edge runtimes, including Cloudflare Workers

Make sure to use the special NeonDB connection pooling URL in your .env file.

DATABASE_URL="postgresql://username:password@neondb.io/dbname?connection_limit=1"


npx prisma init

Create Your Schema in prisma/schema.prisma

model Todo {
  id          Int      @id @default(autoincrement())
  title       String
  description String?
  userId      Int
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

Make a Prisma Client.

npx prisma generate

5. Using the Todo API Endpoints

Now, we’ll create a full RESTful Todo API using Hono and Prisma.

import { Hono } from "hono";
const app = new Hono();
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

// Get single Todo
app.get("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoDetails = await todo.findUnique({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Todo details", todoDetails });
});

// Get all Todos
app.get("/api/v1/todo", async (c) => {
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const allTodo = await todo.findMany();
  return c.json({ message: "All Todos", allTodo });
});

// Create a Todo
app.post("/api/v1/todo", async (c) => {
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoData = await todo.create({
    data: {
      title: body.title,
      description: body.description,
      userId: 1,
    },
  });

  return c.json({ message: "Created a Todo", todoData });
});

// Delete a Todo
app.delete("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const data = await todo.delete({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Deleted a Todo", data });
});

// Patch/Update a Todo
app.patch("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const updatedTodo = await todo.update({
    where: { id: parseInt(id) },
    data: body,
  });

  return c.json({ message: "Updated a Todo", updatedTodo });
});

export default app;

With the code, we have created a full CRUD API for handling todos that:

  • Generates additional tasks to do

  • Fetches both single todos and collections of todos

  • Brings up open todos

  • Removes todos after they are completed

Getting Your Site Online

You can deploy your Hono app to Cloudflare Workers with only one command.

npm run deploy

It only takes moments for your API to go live and start handling requests from everywhere. You do not need to set up servers, configure scaling or look after your infrastructure.

Conclusion

Switching from traditional Node.js + Express hosting to a modern serverless setup with Cloudflare Workers and Hono streamlines development, reduces costs, and eliminates infrastructure headaches. By leveraging serverless architecture, edge deployment, and database solutions like NeonDB with Prisma, developers can build fast, scalable, and production-ready APIs with minimal effort. You can use serverless to focus on what you love, writing great code and delivering powerful web applications.


Frequently Asked Questions

Q. What is serverless deployment and how does it benefit developers?

A. Serverless deployment allows developers to run code without managing servers. Cloud providers like AWS Lambda and Cloudflare Workers automatically handle infrastructure, scaling, and maintenance. This approach reduces operational overhead, lowers costs, and enables faster development cycles.

Q. How do Cloudflare Workers differ from AWS Lambda?

A. Cloudflare Workers run on V8 isolates, offering sub-millisecond cold starts and global edge deployment, leading to lower latency. In contrast, AWS Lambda uses containers, which can result in higher cold start times and regional deployment. Cloudflare Workers are ideal for performance-critical, globally distributed applications.

Q. What is the Hono framework and why is it suitable for serverless applications?

A. Hono is a lightweight, high-performance web framework built on Web Standards. It supports multiple JavaScript runtimes, including Cloudflare Workers, Deno, and Bun. With an Express-like API, Hono simplifies serverless application development, offering fast routing and built-in middleware support.

As Developers, we’ve all been in this situation, using node index.js to start an Express server on port 3000. This method has proved useful for some time, but making it work in production takes a lot of effort.

In traditional deployment, you select a cloud provider such as AWS, GCP, Azure or Cloudflare, rent virtual machines and start to deal with operational problems like:

  • Using Auto Scaling Groups or Kubernetes to manage scaling in a complex way

  • Charging for idle resources when there is little traffic

  • Regular watch over server conditions and maintenance

  • Need to manually deploy and restart after changing the code

  • Organizing what to do during unexpected downtime and failures

These problems take our focus away from the main thing we enjoy, creating code that solves real issues. Is there a way we can do better?

Serverless backend

Comparing Traditional vs. Serverless Deployment

Traditional Node+Express Deployment

Write code Push to GitHub SSH into VM Git pull Restart PM2 Restart application

Serverless Cloudflare Workers and Hono Deployment

Write code npm run deploy Done

The Serverless Revolution

The cloud provider handles the management and provisioning of servers for this kind of deployment, referred to as "serverless." Even though it's called serverless, there are still servers involved. As a result, developers and operators do not have to think about the servers.

Why Serverless is Better Than Traditional Hosting:

  • Build applications using code rather than setting up infrastructure yourself

  • You are charged only for running code (typically very fast)

  • Managing one user or one million is as simple as a flip of a switch without any changes needed.

  • It handles everything for you, no need to update, patch or monitor the server

  • Availability zones are used by default to host your application.

Essentially, in serverless development, you create your API routes, deploy them and the server will handle the rest as the traffic increases.

Setting Up a Modern Serverless Application

A well-structured serverless application usually consists of these items:

Layer

Purpose

Example Services

Frontend

Static site hosting

Vercel, Netlify, Cloudflare Pages

Backend

API functions

AWS Lambda, Cloudflare Workers, GCP Functions

Database

Data persistence

NeonDB, PlanetScale, DynamoDB

Popular Serverless Providers and How They Operate

You have several good choices when selecting a serverless platform:

1. AWS Lambda

AWS Lambda
  • What it is: The first major serverless platform, created by Amazon

  • What's good about it: Works well with other Amazon services like databases and file storage

  • Languages you can use: JavaScript, Python, Java, and many others

  • Best for: Projects already using other AWS services

(AWS Lambda)

2. Google Cloud Functions

Google cloud functions
  • What it is: Google's serverless platform

  • What's good about it: Easy to use with other Google Cloud tools

  • Languages you can use: JavaScript, Python, Go, and Java

  • Best for: Projects that use other Google services

(Google Cloud Functions)

3. Cloudflare Workers

cloudflare workers
  • What it is: A serverless platform that runs code close to users

  • What's good about it: Super fast because it runs in 275+ locations worldwide

  • How it's different: Uses a different technology than the others (V8 isolates)

  • Best for: Projects where speed is important

(Cloudflare Workers)

When Should You Use Serverless?

Serverless isn’t the best tool for every job, but it’s very useful in these cases:

  • When you want to launch quickly
    You don’t need to handle server setup when using Serverless; you can just work on your code. Just write your code, deploy it, and it works!

  • When you're not sure how many users you'll have
    Serverless can automatically deal with increased traffic on your website. No matter how many users you have, the system automatically adjusts for you.

  • When you want to save money on low-traffic apps
    You only have to pay for serverless use when someone uses your app. No visitors means no charges!

Serverless technology is also suited for:

  • Handling events (like when someone uploads a file)

  • Building APIs (the code that apps use to talk to servers)

  • Making small, targeted services

  • Executing tasks at set times

How Cloudflare Workers is Different

How Cloudfkare Workers work

Cloudflare Workers is special in how it runs your code:

Different Technology: Isolates vs. Containers

Most serverless platforms such as AWS Lambda, make use of containers that work like little computers.

  • It takes 300ms-1000ms for a program to start (which is quite slow).

  • Use as much computer memory as possible

  • Not good enough to handle sudden increases in traffic

The technology Cloudflare Workers relies on, called V8 isolates, is the same one used by Chrome to keep tabs apart.

  • The startup time is less than 1ms.

  • Require little space in the system

  • Manage increased traffic without problems

As a result, Cloudflare Workers can be up and running in just one-tenth the time needed by other serverless platforms.

Different Runtime: Not Node.js

Cloudflare Workers doesn’t rely on Node.js which is different from most other platforms. This means:

  • Some features you may have used in Node.js aren’t present

  • You can't reach the files directly.

  • You can’t use some common Node.js packages

  • It measures the use of CPU instead of total running time

If you’ve used Node.js before, this might take a little getting used to.

Problems with Using Raw Cloudflare Workers

Working with Cloudflare Workers on your own can be quite tricky.

  • It gets harder to organize routes as your app gets bigger.

  • There aren’t any automatic systems for handling common activities

  • Responding to requests and sending responses takes much more code than you would think.

Because of this, many developers turn to frameworks like Hono which offer the same benefits as Express.js and solve these issues for you.

Hono: Express-like Development for Serverless

Hono

Hono was created with Express.js users in mind and so it should feel very comfortable to you. Thanks to its size (only ~13KB), this framework now introduces the easy routing and middleware capabilities we love to serverless projects.

(Hono)

Why Hono is Special

  • Familiar API: The app.get(), app.post() functions are used for routing.

  • Fast response: Made for edge networks

  • Built-in middleware: Body parsing, CORS, JWT authentication and additional middleware are included.

  • Platform agnostic: Runs the same on Workers, Lambda, Bun and Deno

You can write code in Hono like this:

app.get('/api/users', (c) => {
  return c.json({ users: [...] });
});

It simply functions, without making any changes, on any serverless platform.

Building a Complete Todo API with Hono

We’ll put the theory into action by building a Todo API that is ready for production with the modern serverless stack. This example shows you how to develop and deploy your application.

1. Making a New Hono Project

With the CLI, you can quickly launch a new Hono project.

npm create hono

At setup, you’ll:

  • Decide on a name for your project’s directory.

  • Choose the Cloudflare Workers template.

  • Verify that dependencies have been installed

  • Pick the package manager that works best for you (npm, yarn or pnpm)

2. Setting Up Local Development

Hono gives you a local development experience that is very similar to Express.

npm run dev

After that, a local development server will be set up to help you test your APIs before they are deployed to the production environment.

3. Adding Database Connectivity with Prisma

We’ll rely on Prisma and NeonDB for the database part of our project.

npm install @prisma/client
npm install prisma --save-dev
npm install @prisma/extension-accelerate

4. Understanding Serverless Database Connections

A key idea in serverless technology is managing how connections are handled. Connection pools can’t be used effectively in serverless environments.

  • Every time a function is invoked, it creates a new connection pool

  • Having idle connections results in wasted resources and makes things more expensive

  • It takes longer for the machine to boot up when it’s a cold start because of the extra time needed to start the connection.

The Serverless Database Challenge
Serverless database connection

There are distinct issues that arise when trying to connect serverless environments to databases.

  • Since workers might run in many edge locations at once, they could use up the database connections very fast.

  • Since the Cloudflare Workers runtime doesn’t use Node.js, many database libraries, including Prisma, cannot be used.

  • The time it takes to make a traditional database connection slows down the first use of an app which impacts the user experience.

This is the reason @prisma/extension-accelerate is needed. It provides:

  • Improved connection pooling for serverless functions with HTTP.

  • Decreased time for the server to become active

  • Saving resources and money

  • Can be used with edge runtimes, including Cloudflare Workers

Make sure to use the special NeonDB connection pooling URL in your .env file.

DATABASE_URL="postgresql://username:password@neondb.io/dbname?connection_limit=1"


npx prisma init

Create Your Schema in prisma/schema.prisma

model Todo {
  id          Int      @id @default(autoincrement())
  title       String
  description String?
  userId      Int
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

Make a Prisma Client.

npx prisma generate

5. Using the Todo API Endpoints

Now, we’ll create a full RESTful Todo API using Hono and Prisma.

import { Hono } from "hono";
const app = new Hono();
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

// Get single Todo
app.get("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoDetails = await todo.findUnique({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Todo details", todoDetails });
});

// Get all Todos
app.get("/api/v1/todo", async (c) => {
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const allTodo = await todo.findMany();
  return c.json({ message: "All Todos", allTodo });
});

// Create a Todo
app.post("/api/v1/todo", async (c) => {
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const todoData = await todo.create({
    data: {
      title: body.title,
      description: body.description,
      userId: 1,
    },
  });

  return c.json({ message: "Created a Todo", todoData });
});

// Delete a Todo
app.delete("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const data = await todo.delete({
    where: { id: parseInt(id) },
  });

  return c.json({ message: "Deleted a Todo", data });
});

// Patch/Update a Todo
app.patch("/api/v1/todo/:id", async (c) => {
  const id = c.req.param("id");
  const body = await c.req.json();
  const { todo } = new PrismaClient({
    datasourceUrl: c.env.DATABASE_URL,
  }).$extends(withAccelerate());

  const updatedTodo = await todo.update({
    where: { id: parseInt(id) },
    data: body,
  });

  return c.json({ message: "Updated a Todo", updatedTodo });
});

export default app;

With the code, we have created a full CRUD API for handling todos that:

  • Generates additional tasks to do

  • Fetches both single todos and collections of todos

  • Brings up open todos

  • Removes todos after they are completed

Getting Your Site Online

You can deploy your Hono app to Cloudflare Workers with only one command.

npm run deploy

It only takes moments for your API to go live and start handling requests from everywhere. You do not need to set up servers, configure scaling or look after your infrastructure.

Conclusion

Switching from traditional Node.js + Express hosting to a modern serverless setup with Cloudflare Workers and Hono streamlines development, reduces costs, and eliminates infrastructure headaches. By leveraging serverless architecture, edge deployment, and database solutions like NeonDB with Prisma, developers can build fast, scalable, and production-ready APIs with minimal effort. You can use serverless to focus on what you love, writing great code and delivering powerful web applications.


Frequently Asked Questions

Q. What is serverless deployment and how does it benefit developers?

A. Serverless deployment allows developers to run code without managing servers. Cloud providers like AWS Lambda and Cloudflare Workers automatically handle infrastructure, scaling, and maintenance. This approach reduces operational overhead, lowers costs, and enables faster development cycles.

Q. How do Cloudflare Workers differ from AWS Lambda?

A. Cloudflare Workers run on V8 isolates, offering sub-millisecond cold starts and global edge deployment, leading to lower latency. In contrast, AWS Lambda uses containers, which can result in higher cold start times and regional deployment. Cloudflare Workers are ideal for performance-critical, globally distributed applications.

Q. What is the Hono framework and why is it suitable for serverless applications?

A. Hono is a lightweight, high-performance web framework built on Web Standards. It supports multiple JavaScript runtimes, including Cloudflare Workers, Deno, and Bun. With an Express-like API, Hono simplifies serverless application development, offering fast routing and built-in middleware support.

Explore other blogs

Explore other blogs

let's get in touch

Have a Project idea?

Connect with us for a free consultation !

Confidentiality with NDA

Understanding the core business.

Brainstorm with our leaders

Daily & Weekly Updates

Super competitive pricing

let's get in touch

Have a Project idea?

Connect with us for a free consultation !

Confidentiality with NDA

Understanding the core business.

Brainstorm with our leaders

Daily & Weekly Updates

Super competitive pricing