Clarifitcations regarding sticky load balancing example architecture by Mathew Hobbis


I have read the example implementation of sticky load balancing by Mathew Hobbis on this link and am slightly confused about a few things.

Was hoping I could get some answers to the following:

Inquiry 1:

Regarding "Consumer Group Clients", is this the same client as LBG Client? or is it a different service?

Question 2 (multipart question):

in the following code snippet for Consumer Group Clients (Assuming that Consumer Group Clients is in the same codebase as the LBGClient):

if (((loop % clientCount) - clientNumber) == 0) {

    consumers[loop].primary = true;

  } else {

    consumers[loop].primary = false;


what exactly is clientCount? Is it the current number of active consumers? or is it the max number (i.e clientCount = queueCount)?

what is clientNumber? is it the identification of the current consumer (i.e clientIndex)? if so how can I know my index If I am brought up dynamically? suppose the scenario with 4 queues and 2 consumers. if I am brought up as a third consumer am I supposed to know in advance that I am the 3rd? is there no way to discover this dynamically?

Thank you very much in advance



  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 487 admin

    Hi @brigadier90 . How's it going? I'll poke Mat and tell him to come take a look at your post here. I'm reading through the blog right now, trying to refresh myself.

    For your Q1, yes I think "Consumer Group Clients" refer to the "load balanced group clients". These are the queue consumers apps that can be added/removed from the group as load dictates. Same thing, different name. Also, I did notice about halfway through the blog a mention of "Consumer Group Consumer", and I think that was meant to be the "CG Admin" process, that kind of keeps track of everything and assigns queues and topic hash subscriptions.

    For your Q2, I'm not sure. On the blog there's a another conditional block snippet:

    If (queuenumber % clientnumber) - clientindex == 0) primaryqueue = true else primary_queue = false

    So I'm guessing (?) that your clientCount is the same as clientNumber which looks to be the current number of clients. And clientIndex is the current index for that particular consumer, which it knows and is configured with when it starts by the "admin" process.

    But I'm just speculating! Ok, enough from me. I'll ask Mat if he can come take a look.

  • brigadier90
    brigadier90 Member Posts: 5
    edited April 2022 #3

    Hi @Aaron! thank you very much for your reply, that does help clarify things. Very much appreciated!

  • mhobbis
    mhobbis Member, Employee Posts: 1 Solace Employee

    Hi @brigadier90, My apologies for duplication of terms. It's a hazard of repurposing material for different groups. In the text a Consumer Group Client is the same as an LBG Client and is the same as the Consumer Group Consumer.

    In terms of the code snippet there are a number of attributes that are related and govern which queues a client thinks it is responsible for -

    • The total number of queues - loop counts through the queues in the snippet.
    • The max number of LBG clients (clientCount) that will run. clientCount <= queueCount
    • The LBG Client number (clientNumber) - an index of the client within the group, e.g., if there are 10 clients each will have a number 0 - 9

    What the code needs to do is work out which of all of the queues that a client is connected to (which will be all of the queues) are primary queues for that client. So if I have 10 queues and 5 clients then each client will connect to all to queues. However, client 0, for example, will treat Q0 and Q5 as primary, client 1, Q1 and Q6 as primary, etc.

    In the LBG Client code once you once you have processed and ACKed your message / completed your transaction, check to see if the allowed time has passed (60s in the blog). If the time has passed has then walk through the list of queues and close and recreate the flows to all queues for which this client does not count as primary. This action will eventually ensure that the client that does count the queue as primary end up servicing it.

    When the LBG client is started it must be started knowing it clientNumber / index within the group.

    I hope that helps. Let me know if you need anything else.


  • brigadier90
    brigadier90 Member Posts: 5

    Hi @mhobbis, Thank you very much for your reply and for the clarification.

    I understand what I must do now.

    Much appreciated, best regards :)

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 487 admin

    @brigadier90 keep us posted on your progress. Let us know if/how it turns out!

  • Piyush Poply
    Piyush Poply Member Posts: 3

    Thanks @brigadier90 @Aaron and @mhobbis for this thread, this helped me too to understand the concept of Sticky Load Balancing approach.. However I am still are unclear on the query that

    How will our client service instances get to know theirs sequence or index number.. Is there a way we can maintain that count and share it accross all the instances of service..

    If there is Such a way then can that be done in Microservice based architecture where all the instances are running on their seperate pods/ docker container