# Netlify serverless functions vs Next.js API Routes?

**URL:** <https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880>\
**Category:** Support\
**Tags:** netlify-api, netlify-newbie, nextjs\
**Created:** [October 6, 2022, 4:31am UTC](https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880 "2022-10-06T04:31:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_coffee](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/_coffee/32/23695_2.png) [@\_coffee](https://answers.netlify.com/u/_coffee)\
**Post date:** [October 6, 2022, 4:31am UTC](https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880/1 "2022-10-06T04:31:43Z")

</div>

I want to build a project with Next.js where I connect to MongoDB Atlas. My understanding is that this is possible through Next.js API Routes and serverless functions hosted directly in Netlify.

Is there reason to choose one approach over another?

Are Next.js API route subject to the same limitations as serverless functions deployed directly in Netlify (10 second time limits, memory usage, number of invocations per month, etc…)?

Thank you!

---

<div class="post-metadata">

**Author:** ![\_coffee](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/_coffee/32/23695_2.png) [@\_coffee](https://answers.netlify.com/u/_coffee)\
**Post date:** [October 8, 2022, 1:51am UTC](https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880/2 "2022-10-08T01:51:11Z")

</div>

Bump on this thread.

In particular, is this approach of connecting to MongoDB atlas via Next.js API routes on Netlify possible?

> **[MongoDB with JavaScript - MongoDB Documentation - MongoDB Docs](https://www.mongodb.com/docs/languages/javascript/)**
>
> Explore JavaScript and TypeScript integrations with MongoDB, including Node.js driver features and support for MERN and MEAN stack applications.

I’m a bit confused after reading this thread:

> [@\[Support Guide\] Can I run a web server, HTTP listener, and/or database at Netlify?](https://answers.netlify.com/t/support-guide-can-i-run-a-web-server-http-listener-and-or-database-at-netlify/3078):
>
> Last reviewed: July 2025 How do I run a server/database at Netlify? We often get questions about how to run a specific backend server or database at Netlify. Examples of these types of questions include: How to I get my node HTTP listener to respond to requests? How do I start Mongo/MySQL/\<insert-some-database-here\> running on the server? How can I SSH into my website? We are here today to answer these questions - and the answer is: you can’t! hushed_faceWhat do you mean, I cannot run a …

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [October 9, 2022, 4:40pm UTC](https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880/3 "2022-10-09T16:40:12Z")

</div>

Hey @_coffee,

Sorry for the delay.

Under the hood, there’s no difference. They both run on Netlify Functions, and thus, are subject to same limitations. But on the surface, there are these differences:

Choose to use Next.js API routes when:

- You wish to keep all your application logic is the same structure. For example, if you already have other API routes, or if you’re more familiar with Next.js API, then using that makes more sense.
- You need some Next.js-specific functionality. In this case, it’s an obvious choice.
- You wish to avoid vendor lock-in. If you choose to stop using Netlify (we hope you don’t 🙂), you can simply take your Next.js codebase and deploy it elsewhere, instead of having to convert your Netlify Functions into some other format.

Choose Netlify Functions when:

- You wish to avoid Next.js overhead. It goes without saying that, if you use Next.js API routes, Next.js will do its own processing, which leads to bigger function bundles and a slight delay in function execution time.
- Debugging could be easier. For each function, you’d get a separate log, which can make debugging easier, as opposed to just one API handler function in case of Next.js API routes.
- You wish to use Netlify-specific stuff like On-demand Builders, Scheduled Functions, etc.

This is a rough comparison between the two.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [October 9, 2022, 4:41pm UTC](https://answers.netlify.com/t/netlify-serverless-functions-vs-next-js-api-routes/76880/4 "2022-10-09T16:41:27Z")

</div>

To answer your Mongo question, yes that would most likely work with or without Next.js API routes (that is, by using Netlify Functions directly). So, you can choose either way.
