I am trying to design a Rest API backend based on Loopback. Since I heard nodejs is not very good in computing since it will block the thread, can I make a async call just for using java to calculate them, but also host them on same server where the nodejs application is running.? This way it willbecome non blocking. Is it a good idea to , say if hosting on a AWS ec2 instance, host tomcat server and nodejs nginix server on same instance?

  • hosting on the same server makes sense when CPU capacities would otherwise go to waste, but it's recommended to aim for a lot less than 100% utilization so that you can still deal with load peaks. There's no particularly strong reason to use Java though, e.g. you could use a second NodeJS instance for the background tasks. Or you could keep the compute-intensive task within the REST server, but load-balance across multiple instances of the REST server. That's likely much simpler, although it may have worse latencies.
    – amon
    Apr 27, 2020 at 16:11

2 Answers 2


Technically what you are suggesting is very feasible. It's something that is quite common, in fact. In the past, there were limited options on sizing a machine and therefore it was necessary to do this in order to use computing resources efficiently. There are a lot of challenges, however, which largely explain how we got to where we are with virtual machines, containers, and serverless architectures. AS others have already noted, trying to manage the capacity with regard to load will be complicated and you will end up needing to oversize your VM to meet peak loads.

Since you mention AWS, you should understand that a lot of the options available there are designed to help avoid theses challenges. The design you mention fits very well into containers e.g. a Kubernetes pod. There are many options to allow for scaling under heavy loads while avoiding paying for the extra capacity when you don't need it. You should probably also look into lambdas which cost nothing when not actively in use.

So yes, you can do this but it's a pretty out-dated approach. Given the options you have available to you, there doesn't seem to be a good reason to go this route.

  • So how will I do using lambda then .. I still need to get the data from front end and via the API? because the video/static file will be uploaded via a web UI/UX front end
    – Makjb lh
    Apr 27, 2020 at 21:24
  • Details on how to use AWS is beyond the scope of this forum (Software Engineering.) You should be able to find tutorials and instructions that walk through this and stackoverflow is a resource as well. I will note that I found using the API gateway with lambdas very simple (and cost effective) but if you are need to use loopback, that might require at least a container and some networking config.
    – JimmyJames
    Apr 28, 2020 at 14:31

Node.js is normally IO-bound, so you can indeed run another service on the same instance, just make sure both heaps fit in memory.

However, as soon as you start getting CPU stalls, it will affect your Node.js latency. So make sure your CPU usage is within reason by load-testing your backend.

Investing in separate instances may be a better option in the long term, because you’ll be able to scale them separately.

  • If we are crating seperate instance or not, still will it not create another thread or something ?
    – Makjb lh
    Apr 27, 2020 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.