The Wayback Machine - https://web.archive.org/web/20211223112140/https://github.com/vercel/next.js/discussions/17679
Skip to content

Are there any downsides or limitations of using Next.js api routes instead of custom server? #17679

Answered by lfades
mimoid-prog asked this question in Help
Are there any downsides or limitations of using Next.js api routes instead of custom server? #17679
Oct 7, 2020 · 5 answers · 9 replies

I have a huge backend application using Express, with many routes, middlewares, databases etc. Is it possible to recreate all of these features and others using Next.js API routes and is it worth to do so? What are the downsides of using API routes?

Replies

5 suggested answers
·
9 replies

In case you decide to use a custom server, you'll implement your own route patterns.

A custom server can not be deployed on Vercel, the platform Next.js was made for.

Before deciding to use a custom server please keep in mind that it should only be used when the integrated router of Next.js can't meet your app requirements. A custom server will remove important performance optimizations, like serverless functions and Automatic Static Optimization.

More info: https://nextjs.org/docs/advanced-features/custom-server

1 reply
@mimoid-prog

@francisrod01 Yeah, I know about the custom server and it's downsides but im curious if I can achieve the same thing by using API routes and If I won't be limited in same way when my backend will get more complex.

Serverless functions scale better, are faster, and cost less. The only limitation afaik is that you can't have live connections (like websockets), because that would require the serverless function to stay alive.

8 replies
@andrzejchmura

One thing to keep in mind, if you are planning to deploy on Vercel, is that there are limitations on the number of serverless functions allowed per deployment: https://vercel.com/docs/platform/limits

@timneutkens

One thing to keep in mind, if you are planning to deploy on Vercel, is that there are limitations on the number of serverless functions allowed per deployment: vercel.com/docs/platform/limits

It's very unlikely you'll run into these when using Next.js as in general only 1 function is deployed for API routes.

@andrzejchmura

That's awesome! Was that always the case? I remember having a hard time deciding if this limitation wont affect me too much, but now I see additional note added to /limits page. Anyway, that's great to hear.

@wizzymore

I know this is an old thread but this was the first result when searching for next.js api limitations and i want to address one issue @andrzejchmura mentioned, based on what vercel says on the link provided i don't think you will ever reach the limit on a normal project with the hobby plan:

Note: Next.js bundles all API Routes and server-rendered pages into shared Serverless Functions , separating API routes and server-rendered pages when deployed on Vercel. Further Serverless Functions are created only if they do not fit within the 50MB limit. As a result, the "Serverless Functions per Deployment" limit is unlikely to apply for Next.js projects.

Answer selected by lfades

Note: Really sorry if it's a silly question (hehe) I am trying to learn nextjs ☺️

0 replies

I'd be keen to know this. Is it suitable for a social media-like application using GraphQL? Will need posts, comments, upvotes, real time notifications etc. I know Lambdas don't maintain the sockets after cool down, but it seems like such an efficient way to build and deploy. What's the alternative? Spin up a separate AppSync / Apollo server to handle subscriptions?

0 replies

Hi @mimoid-prog, how did your transition to api routes go? Would you mind to share your experience? Especially with db connections 🙂

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
10 participants