API request routing specific same node.

26 views
Skip to first unread message

pradeep c.s

unread,
Apr 5, 2024, 12:48:48 PM4/5/24
to nats
I am using nats.io for micro service api calls.
In distributed environment, I want to connect specific node/pod based on hashcode.
is this possible in nats.


for example :

There is eCommerce application which supports multiple vendors to sell their products.
Product category might be dynamically updated. if new  Product catalog added, all API requests supposed to go to one specific node/Pod.

Here, we are expecting first request can go to any specific Node/Pod. Next time onwards same request should go to specific Node/Pod. Current system is implemented with legacy manner. each hash code gets cached at LB pool and routes to specific node.  We need to try this use case for nats. 


What is better suggestion here. 

Jean-Noel Moyne

unread,
May 5, 2024, 8:44:01 PM5/5/24
to nats
Have you looked at the subject mapping functionality (which has a function that can take one (or more) of the tokens in the subject and insert a partition number that is calculated using consistent hashing)?

derek

unread,
May 5, 2024, 8:46:41 PM5/5/24
to nats
You really do not need to do that type of an architecture. In NATS everything is bound to subjects. So if you want to think in terms of an app having some data loaded and in memory after an initial request, you could do the following.

1. Use a DQ to load balance initial requests (with geo awareness in super clusters).
2. Create an Inbox and respond to the initial request with this inbox (the app will subscribe to it as well during processing of initial request), and the requestor will send subsequent requests to the inbox and hence this app.

=derek
Reply all
Reply to author
Forward
0 new messages