Next.js is both a backend + frontend framework?
Unanswered
Singapura posted this in #help-forum
SingapuraOP
For background reference, i come from java spring boot field where i create backend API, deploy it to aws and work with cloud providers such as aws. And then i build the frontend separately in react or angular.
I just finished a 5h+ course on youtube to learn nextjs on a deeper level and it uses Prisma ORM. By using Prisma i realized it takes care of all the CRUD operations.. there was not a single need or usage of backend service. No need for cloud providers, aws or anything similar.
Turns out the whole backend is built and cluttered within the frontend of a nextjs app..?
Please tell me how is this a good idea?
What if i want to scale the backend because of high load pressure by creating more replica sets? What about load balancers? What if i want my backend to become a microservice architecture? How do i unit test the backend if it's cluttered among the frontend? There are so many questions here..
I am very confused about how i would go about nextjs development. The only thing that interested me into learning nextjs is extremely high performance and caching that i keep seeing on all websites built in nextjs.
If i want to build my backend separately as a java spring boot app for example can i still integrate it with nextjs or is nextjs strictly intended to be used as both backend + frontend?
I just finished a 5h+ course on youtube to learn nextjs on a deeper level and it uses Prisma ORM. By using Prisma i realized it takes care of all the CRUD operations.. there was not a single need or usage of backend service. No need for cloud providers, aws or anything similar.
Turns out the whole backend is built and cluttered within the frontend of a nextjs app..?
Please tell me how is this a good idea?
What if i want to scale the backend because of high load pressure by creating more replica sets? What about load balancers? What if i want my backend to become a microservice architecture? How do i unit test the backend if it's cluttered among the frontend? There are so many questions here..
I am very confused about how i would go about nextjs development. The only thing that interested me into learning nextjs is extremely high performance and caching that i keep seeing on all websites built in nextjs.
If i want to build my backend separately as a java spring boot app for example can i still integrate it with nextjs or is nextjs strictly intended to be used as both backend + frontend?
26 Replies
Bengal
i saw a video that i think would be valuable for this question:
https://www.youtube.com/watch?v=Rrz2q5uCHdE
https://www.youtube.com/watch?v=Rrz2q5uCHdE
@Bengal i saw a video that i think would be valuable for this question:
https://www.youtube.com/watch?v=Rrz2q5uCHdE
SingapuraOP
Just watched it. i didnt hear anything positive about nextjs. it appears to me as if nextjs is great for smaller low budget projects, but definitely not for large scale projects that may have thousands or millions of users?
all this time i thought nextjs is a frontend framework. a react-killer. spent so many days learning it just to find out it's a full stack framework.
kind of disappointed because the way of how backend + frontend gets cluttered, is very easy to see how messy this can become no matter how much you try to modularize the code
it also seems like i dont have enough flexibility to control the backend. everything feels kind of forced, not to mention the forced function, folder, parameter names etc
kind of disappointed because the way of how backend + frontend gets cluttered, is very easy to see how messy this can become no matter how much you try to modularize the code
it also seems like i dont have enough flexibility to control the backend. everything feels kind of forced, not to mention the forced function, folder, parameter names etc
SingapuraOP
I want to like nextjs but im having mixed feelings rn. @Bengal can you tell me in your own words something about nextjs that i missed or misunderstood?
would it be fine to build my own backend and use nextjs
would it be fine to build my own backend and use nextjs
/api/ folder to fetch those routes from the backend? therefore i'd use nextjs strictly only for frontend and my own custom backend only for backendCalifornian
afaik, you can have a separate backend (outside of the Next.js app) and don't use Next.js route handlers at all . Then, you fetch the endpoints of your backend in Next.js server components.
one thing is, Java is also a runtime like Go, Python or whatever. So Next.js needs a runtime, which is Node.js, V8 isolates.Indeed Vercel is working on Pyhon and Go runtime in Next.js, which deploys to AWS lambda. plus Vercel splits codes across aws and cloudflare instances. especially it works with I/O bound services like Chatbots.
@tafutada777 one thing is, Java is also a runtime like Go, Python or whatever. So Next.js needs a runtime, which is Node.js, V8 isolates.Indeed Vercel is working on Pyhon and Go runtime in Next.js, which deploys to AWS lambda. plus Vercel splits codes across aws and cloudflare instances. especially it works with I/O bound services like Chatbots.
SingapuraOP
the project i need to build is similar to onlyfans. so imagine onlyfans architecture. login/registration. real time chatting. creating text/image/video posts in profile timeline. push notifications. stripe payment subscription integration
i always avoid 3rd party paid services as if my life depends on it, because they're paid. the free tier is there just as bait to get you to use their sdk, and once you're wrapped with their ecosystem it's only a downward spiral of death from there. not worth it. that's why i chose https://socket.io/ for real time chatting
the issue i have with nextjs is. what if 6 months later i realize i need to build a mobile app? how am i going to use the backend, built in nextjs, that's cluttered with nextjs frontend, for android/ios app?
the mess just keeps piling up
in my case i deploy a next.js on GCP k8s along with Go, Rust, Python and Node.js+GraphQL.
Plus Vercel Edge Runtime for Chatbot, which runs on Cloudflare Worker.
@Singapura the issue i have with nextjs is. what if 6 months later i realize i need to build a mobile app? how am i going to use the backend, built in nextjs, that's cluttered with nextjs frontend, for android/ios app?
Red-naped Sapsucker
next.js, as far as I understand it, first and foremost is a framework to build SSR applications. you can build an API with it, but this is not one of it's strengths. if you have advanced requirements for your API, you can, and probably should, set up a separate project for that
@Red-naped Sapsucker next.js, as far as I understand it, first and foremost is a framework to build SSR applications. you can build an API with it, but this is not one of it's strengths. if you have advanced requirements for your API, you can, and probably should, set up a separate project for that
SingapuraOP
What are the advanced requirements? What if at the begging there are none but later down the rabbit hole as the project gets more complex it requires more advanced stuff built in?
I can't predict everything ahead of time
Red-naped Sapsucker
As I said, you can build an API with nextjs. If that doesn't work for you anymore, for whatever reason, port it to a separate project and use whatever framework you see fit
@Singapura What are the advanced requirements? What if at the begging there are none but later down the rabbit hole as the project gets more complex it requires more advanced stuff built in?
Nice thing is that Next.js can always be used as a middleman between your real Back-end server
Also that your next.js client can always hit up a different back-end than your Next.js endpoints
Also that your next.js client can always hit up a different back-end than your Next.js endpoints
So what I mostly see people do is for simple request and response and rendering -> use Next.js
If you want to add Realtime capability, -> hit up a 3rd party back-end server to establish long-term connection/handshake using websocket
If you want to add Realtime capability, -> hit up a 3rd party back-end server to establish long-term connection/handshake using websocket
@Singapura the issue i have with nextjs is. what if 6 months later i realize i need to build a mobile app? how am i going to use the backend, built in nextjs, that's cluttered with nextjs frontend, for android/ios app?
You can always skip the Next.js backend too if you don't like to be cluttered with next.js back-end
Next.js API Handler is supposed to accomodate the use of server connection from Client components AS WELL AS external Applications that wants to connect to Next.js server as a simple provider of simple request and response back-end logic.
You could always say, use Flutter and directly connect to DB and handle the back-end logic and not touch Next.js at all, or you could just add some more endpoint in Next.js backend and hit the DB that way.
I might be messy but its just a matter of connecting the strings
Next.js API Handler is supposed to accomodate the use of server connection from Client components AS WELL AS external Applications that wants to connect to Next.js server as a simple provider of simple request and response back-end logic.
You could always say, use Flutter and directly connect to DB and handle the back-end logic and not touch Next.js at all, or you could just add some more endpoint in Next.js backend and hit the DB that way.
I might be messy but its just a matter of connecting the strings
Red-naped Sapsucker
I mean it's really not that complicated. If your app keeps growing, you should add layers of abstraction anyways, to prevent strong coupling between modules. So at some point you move your business logic to a separate module and then it's easy to move that module to a different project as well, if you see the need for it
@Singapura Just watched it. i didnt hear anything positive about nextjs. it appears to me as if nextjs is great for smaller low budget projects, but definitely not for large scale projects that may have thousands or millions of users?
Bengal
I think he didn't say "next.js is low tier", I believe he just said that it serves a certain purpose
From my understanding, if next.js can fulfil your project's requirements and works well for your use cases, then you don't need more than next.js
It's just a tool and it's "good" as long as it fullfils its purpose
If you need a seperate backend using any other technology when your app scales, that doesn't mean there's something wrong with next.js
It still provides a robust solution instead of just working with react, in the frontend part
Also apparently the definition of "frontend" and "backend" can change depends on who you ask