For simplicity’s sake, let’s take the load balancer out of the picure for now. Let’s go with the most basic flow that involves two different XMPP domains (each consisting of exactly one server)
|Client A| |Client B|
|Server A+--->|Server B|
An end-user of Domain A uses a software client, Client A that is connected to any of the XMPP servers in its domain. In this example, there’s just one server in the domain: Server A. The connection between Client A and Server A is called a Client-to-Server (C2S) connection. Similarly, an end-user in Domain B, using Client B, is connected to Server B using a different C2S connection.
When the end-user that uses Client A wants to send a message to the end-user that is using Client B, the message will be composed on Client A, and delivered to Server A.
Server A wil inspect the addressing information on the message, and will determine that the message is addressed to a user on a different XMPP domain than the domain that Server A is part of. As a result, the server will use DNS to look up what servers are part of Domain B, and will establish a connection to one of those servers. In our example, there is only one server in Domain B: Server B. Server A will establish a connection to Server B (called a Server-to-Server or S2S connection), and use that connection to deliver the message that it recieved from Client A to Server B.
Server B will again inspect the addressing of the message. It will discover that the message is addressed to a client that is part of its domain. If it determins that the client is connected, it will deliver the message to Client B.
When any of the domains consists of more than one server (when clustering is being used), then there might be some cluster-internal routing when the cluster-node that receives the message isn’t the same cluster-node that has a previously-established connection to the intended recipient. This cluster-internal routing is not specific to XMPP. Openfire largely depends on the Hazelcast library for this. The clustered networks are expected to be high-availability and high-capacity networks. Apart from the largest of properitary use-cases, there is little risk in that becoming the first scalability issue that needs to be dealt with.