Home > Mobile >  Why does backend development need a seperate server?
Why does backend development need a seperate server?

Time:12-29

I am developing my own website. So far, I've used React for the frontend and Flask for the backend. I've been doing frontend development for a while now but I'm just starting to get into the backend.

From my limited understanding, frameworks like Flask and ExpressJS create their own servers and host data that the frontend can use. It seems to me that that they automatically create websites to host and receive data. In my website, I route the backend to do what I want and use fetch requests with POST and GET from the frontend to communicate.

Although it works, to me, it seems overly complex. Why does the backend need it's own server? It seems unnecessary to create a proxy for the frontend and fetch data. Why can a website not just run custom code in the background, why does it need a service like Flask or ExpressJS to run in the background for it? These backend frameworks run Python or NodeJS in the background, but wouldn't it be much simpler if the website itself could run Python or NodeJS in the background?

I also see that in frameworks like React, you can import things and use modules— like in NodeJS. While importing some modules works, the require keyword is not allowed and normal NodeJS code will not work. Therefore, the backend will not work. Why is this— why can't you just run backend code natively? Instead you have to go through fetch and specify headers to basically translate information from your frontend to your backend.

Forgive my amateur understanding of web development, but the frontend/backend system seems overly complex to me. Thanks in advance.

CodePudding user response:

its usually much better to deploy front end and back end on separate servers because

I did some research and I found this helpful post on reddit and some posts on quora about the question

https://www.quora.com/Should-a-backend-application-be-separately-deployed-from-a-frontend-application

https://www.quora.com/Should-the-front-end-back-end-and-database-run-on-different-servers-or-a-combined-server

reasons to deploy your app to separate servers


  • to upgrade the front end you wont have to shutdown the whole server
  • it can be faster

some problems this may cause


  • deploying onto separate servers can cause problems with CORS
  • you might have to use different repositories

however you don't always need separate hardware and you could use something like a docker container or a virtual machine

CodePudding user response:

Why does the backend need it's own server?

Where will the client store data so that when you open the page again the data will still be there? You can use localStorage but this is locked to that particular browser. What if someone logs in on a different device or uses a different browser?

Where will the client get the application from in the first place? Your application needs to be packaged up in a form that can be easily downloaded, and it needs an address to be loaded from. This is all considered "back end" even if you're using a static hosting service like GitHub Pages.

There's a lot of reasons why a back-end exists and needs its own server. Any application with persistent state which is expected to work across different sessions needs at least one of these.

  • Related