Is it a bad practice to handle client's web page / static files requests and REST API requests on the same express server? [closed]

145
February 28, 2021, at 03:20 AM
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed yesterday.

Improve this question

I've got a web app (single page React app) and I have an express server hosted on cloud run that handles all of my users' requests.

But I have some /api routes which right now are being handled on the same server. They usually call an external API or update something in the database.

For example:

/api/send-contact      // SENDS CONTACT FORM EMAIL
/api/search            // HANDLES TEXT SEARCH AND RESPONDS
/api/update-viewcount  // UPDATES THE DB VIEW COUNT FOR A PAGE

Is it a bad practice to handle those /api calls on the same express server that I use to respond to user's page requests? Should I build a separate server just for those "API" calls?

Answer 1

Server architecture contains many tradeoffs. To get higher scale, you typically add complexity (server clustering, offloading static resources, dynamically spinning up more servers, etc...). But, you don't want to add unnecessary complexity as that may cost more and is more complicated to manage and monitor and maintain.

So, offloading static resources to some other server (a CDN or an NGINX instance or something like that) is one path on the road to adding scale to your server. But, you would only go there when you have a specific server scalability motivation for doing so. If your server is operating at 30% capacity now, there's no reason to go there yet.

Is it a bad practice to handle those /api calls on the same express server that I use to respond to user's page requests?

No. Not if your server is able to handle your current load just fine.

Should I build a separate server just for those "API" calls?

No. When you need more server scale and you've finished doing simple server optimizations to improve your scale, then you would consider getting some things off your API server such as serving static resources.

READ ALSO
How to display JSON list for each hour of day - Java, SpringBoot

How to display JSON list for each hour of day - Java, SpringBoot

I am mapping JSON data to object model in SpringBoot, looping through it and displaying it in the console

115
Use Anaconda environment in Atom (Mac OS)

Use Anaconda environment in Atom (Mac OS)

I am working on Mac OS and installed AtomI was wondering if there's a way to make all the packages from my anaconda3 environment available in Atom

121
Get column type from schema in Laravel 8

Get column type from schema in Laravel 8

I'm getting some columns from various tables within my project and would look to obtain some additional information other than the column name, I'd like to get the column type as well

166