Communication between RESTful APIs on the same server with NodeJS

I am creating two sets of services on a website (all written in NodeJS on the server), both use a RESTful approach. For modularity, I decided to make both services separate objects. The first service relates to the products of the site, and the second specifically relates to user-related functions. Thus, the former can have functions like getProducts, deleteProduct, etc. The second will have functions like isLoggedIn, register, hasAccessTo, etc. The product module will make multiple calls to the custom module to ensure that the caller is privileged to do so.

Now the reason I separated them was because I foresee a roll-out of a separate product in the near future, but it will need to use the same user system as the first (even sharing the same database). The custom system will use a database covering the entire site and all subsequent products

My question is about the relationship between these projects and the users project. What is the most efficient way to split the users module without any significant speed hits. If the product API made a UI API call on the same server (localhost), is there significant cost to do this, as well as to create a custom API in each successive project? Is there a better way to do this through interprocess communication? Is the custom API just running as its own service an efficient solution?

+3


source to share


1 answer


If you have two nodes on the same server (machine), then you have decent performance in terms of network latency, because they are on the local host. The nodes will then exchange messages using the rest api, so on the metro you will be using node js sockets. You could use unix sockets instead of http sockets because it's faster but worst to debug, so I recommend you don't (but he knows the alternatives well).

Finally, your system looks like an "Actor Design Template". At first glance, this design pattern is a bit tricky to understand, but you could take a look at it if you want more information on the Actor Model Pattern:



+2


source







All Articles