Next.js or React for microservices app?
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Is this good?
I am going to create a microservice web app, where the UI and backend are separated.
However, I'm not quite sure which practices are best for both frontend and performance.
I'm considering two technologies: Next.js (fullstack) and React (frontend).
I plan to use Next.js because:
- It's still React.
- It has a useful server action that, in my opinion, is more secure than React which making HTTP requests directly from the client, which can expose API endpoints.
- It has easy routing.
Why am I considering just using React?
- React is only for the frontend.
- Data fetching is done directly from the client, without using a server action as an intermediary.
Based on the above, I'm wondering:
What do you think, guys?
I am going to create a microservice web app, where the UI and backend are separated.
However, I'm not quite sure which practices are best for both frontend and performance.
I'm considering two technologies: Next.js (fullstack) and React (frontend).
I plan to use Next.js because:
- It's still React.
- It has a useful server action that, in my opinion, is more secure than React which making HTTP requests directly from the client, which can expose API endpoints.
- It has easy routing.
Why am I considering just using React?
- React is only for the frontend.
- Data fetching is done directly from the client, without using a server action as an intermediary.
Based on the above, I'm wondering:
If I use Next.js with server action to interact with APIs on another server and routing managed by the backend, could its performance be inferior to React.js, where routing and data fetching are done on the client side?
What do you think, guys?
2 Replies
IMHO, Next.js in more elastic when you want to optimize app, even when it's only frontend usage, but still you can use any of it's features like SSG, ISR or dynamic routes to easly optimize your frontend. Also you can create micro-frontends to modularize whole app 😄
If your app is NOT a public facing app where a good SEO, page caching, etc is needed then just React is good. It would be cheaper to host as you'll just have static files. That means that all 3rd party integrations you do should go to the API and not talking to them directly from React (as you might leak credentials).
If you're not the one building the API though and the API is hosted somewhere else then you want to have more freedom on the 3rd party integrate then you need your own server - so Next.js would be the correct pick - ex. you want to store images to S3 but the API team don't need that for other parts of the app then you can build it "locally" in the Next.js backend.
If you are wondering if you should go and build the whole App - frontend + backend API in Next.js you might not actually need API? If you need API so your clients can integrate with the app then you might want that API to be external so it scales separately.
If you are trying to build a MVP of your app just go with Next.js as the development is fast and this is what you want in the begining of such journey.
If you're deciding something for a few years ahead then IMO it's worth spending 1-2 weeks in experimentation - go build PoC of the two variants and check what works best for you.
If you're not the one building the API though and the API is hosted somewhere else then you want to have more freedom on the 3rd party integrate then you need your own server - so Next.js would be the correct pick - ex. you want to store images to S3 but the API team don't need that for other parts of the app then you can build it "locally" in the Next.js backend.
If you are wondering if you should go and build the whole App - frontend + backend API in Next.js you might not actually need API? If you need API so your clients can integrate with the app then you might want that API to be external so it scales separately.
If you are trying to build a MVP of your app just go with Next.js as the development is fast and this is what you want in the begining of such journey.
If you're deciding something for a few years ahead then IMO it's worth spending 1-2 weeks in experimentation - go build PoC of the two variants and check what works best for you.