Search code examples
node.jsreactjsserverweb-applicationsserver-side

What is the real need of building a server for a web application?


I've been learning web development for the past 3 months, so I'm pretty new to it. Since 3 months, I've been working on the client-side of applications using React, and i can build somewhat usable websites using just this. I have even used firebase in some of my projects for the real-time database and for authentication as well. So, when i was able to do all this on the client-side, naturally i started to question the need of a server, or more specifically, server-side scripting. Everywhere I've looked, the most highlighted aspect of server-side scripting was dynamic rendering of webpages. But that can also be done on React and pretty easily. So what is the real need of server-side scripting? Why would I even want to build a server using a server-side language such as NodeJS?


Solution

  • To add to what others have failed to mention: cost and security.

    The most valuable thing a company owns is its data. Some of that data is proprietary, some of it may be regulated by law, some of it is personal to a customer but needed in order to do business with them. That data has to be kept safe, and only given to people who are allowed to have it and will safeguard it properly.

    Very very few companies allow their database hosts to be accessible directly from the internet. It makes it too easy for attackers to focus their efforts to get at that data.

    API services, typically REST or SOAP, grant you the ability to verify someone is allowed to access the data in question, and refine and filter irrelevant data or data they aren't allowed to see from the query prior to sending it into the internet to an end user's computer. You don't want any more data to leave than absolutely necessary for the user to perform some meaningful action. This is for the same security concerns as above, but also to be nice to the user's machine. You don't want to bog their client down with data they don't need, as it slows everything else down.

    From the cost angle, any computing you can do on the client machine is free. By moving as much as possible to the client, especially calculations applicable only to their session, that frees your service up to serve other requests for other users. Server side rendering was expensive to scale because every rendering cycle had to be calculated on the server for each individual, converted to html and sent back before the next request could be handled. In order to reliably serve more customers required many more server hosts to keep up with the traffic.

    You need to be careful not to move too much to the client, as their device capabilities are unpredictable. It could be a phone, an old laptop, or a gaming pc. If you assume everyone is on a gaming pc and push too much to the client, you'll end up limiting your site to only being functional for users with high end computers.

    As a final piece of advice, it never hurts to ask that question in class. Chances are your classmates would benefit from it as well.