Understanding Typesense's High Availability Setup

TLDR Imtiaz asked about Typesense's server assignment logic for high availability setup. Jason clarified the round-robin mechanism and advised against client reinitialization. Alex queried about traffic routing to geographically nearest nodes.

Photo of Imtiaz
Imtiaz
Mon, 25 Oct 2021 02:38:29 UTC

Hi. New user almost ready to take our first typesense system into production. Would just like to thank all the contributors to the project for the amazing work. :tada: *edit:* found a bug on my end, solved :slightly_smiling_face: ~Just had a query with regards to a High Availability setup - I have 3 servers ready to go. I am using the `typesense` js client in the browser, and I noticed it always chooses server-a (the first node on the list). I had a look at ApiCall.ts and it appears as if all the servers are healthy it would always use the first one.~ ~My questions are:~ 1. ~Is this by design - and is there any reason it applies this logic?~ 2. ~Would it not be better to share the load between the 3 servers instead of always choosing the first?~ 3. ~If sharing the load would benefit the overall performance, is there any API on the client I could use to do this, or should I just randomise the nodes before initialisation?~

Photo of Imtiaz
Imtiaz
Mon, 25 Oct 2021 02:48:25 UTC

I actually noticed this snippet now: ``` // Attempts to find the next healthy node, looping through the list of nodes once. // But if no healthy nodes are found, it will just return the next node, even if it's unhealthy // so we can try the request for good measure, in case that node has become healthy since getNextNode(requestNumber: number = 0): Node { ...``` So I assume the expected behaviour is for the search requests to get spread across the 3 nodes. Would it always start with the first node, and when does it switch to the next node (I have not seen any searches hit the other nodes yet, but they are online and healthy)

Photo of Jason
Jason
Mon, 25 Oct 2021 03:07:53 UTC

Imtiaz Each instance of the client will round-robin requests between the three nodes. When you instantiate the client, it will indeed send the first request to Node 1, but subsequent API calls will cause the request to go to Node 2, then Node 3, then Node 1, 2, 3 and so on

Photo of Jason
Jason
Mon, 25 Oct 2021 03:10:33 UTC

If you’re not seeing requests go to other nodes, one potential reason could be that the entire client is reinitialized on each request…

Photo of Alex
Alex
Thu, 18 Nov 2021 20:14:52 UTC

Regarding node selection is there any attempts at directing traffic to the nearest node geographically?

Photo of Jason
Jason
Thu, 18 Nov 2021 20:24:19 UTC

Just responded here: