Sunday 27 January 2019

I'm building a web app and I need some feedback on the way I decided to handle the backend structure.

I posted this question before in r/webdev and I didn't got a good answer so I'll post it again here.So I'm using reactjs and nextjs on the frontend and nodejs, mongodb on the backend. Now the thing is that I have two servers running for this application. The first one is the nextjs(well it's a nodejs server but you get the idea) which I only want to use to pass the request params on the front end, basically for just rendering the correct pages based on url and then use these params to call another server which handles everything else. To differentiate the servers I use /api/ for the second one.The second server interacts with the database but the database is on mongodb atlas(I do plan to move it to a separate server tho). Also I plan to use nginx load balancers so if one server goes down the app is still up and running. And just to make it clear I don't have separate machines as severs, the servers both run on the same machine with different ports.Also here is a scenario where, at least in my mind, makes sense to have a separate server for the ui. So the users loads a page and the first server sends the ui elements which needs to rendered. Now a request to the second server is made in order to get the data for the page. Let's say that the page has many comments and I just show 30 of them, if the user wants to see more he only needs to make a request to the /api/ server and leaves the ui server free for other users. So if I see the that the /api/ is under load very often and the ui one isn't I can just add another /api/ server to scale the app. Again I'm new to all of this so if this doesn't make sense please let me know.

Submitted January 27, 2019 at 10:56AM by 0xde908cb

No comments:

Post a Comment