Search code examples
aeron

Mutliple clustered services message filtering


I am currently running two clustered services inside Aeron Cluster. There is a single consensus module context with two services, each having separate ClusteredServiceContainer.

I've created a disjoint set of SBE messages for each one of them since they have different functionalities.

When I send any message to the cluster, both services see them. I can filter them out by schemaId inside each service, but they still go via RAFT consensus and will be replayed on restart. This is something I would like to avoid.

What are the possible solutions to run multiple clustered services within the same cluster instance and make sure that they see only relevant messages?


Solution

  • What is happening is very much by design and is desirable. Let me explain why.

    As long as the services are hosted by the same Aeron Cluster (and you are free to chose it this way), all the nodes of the cluster will get the incoming messages, whether they are destined for ServiceA or for ServiceB.

    The reason is that they are part of the same cluster and clustering requires all participant nodes of the cluster to have the same state all of the time (well, almost all of the time). Without that, the cluster can not provide the guarantees that it is supposed to (fault tolerance if one node goes down and another seamlessly catches up, etc.).

    This is independent of how many "Clustered Services" you are running in the cluster; that is your application logic distribution choice and orthogonal to the "clusterness" of the Aeron Cluster.

    If you want it differently, you could make two separate clusters, let us say C1 and C2. Then implement some cluster services, s1 and s2 let us say, in C1 and s3 and s4 in C2. That way, messages going to S1 and S2 will only be replicated to the nodes of C1, and messages going to s3 and s4 will only be replicated to the nodes of C2.

    You basically have to think about the architecture: Which set of application logic cluster services(s) you want to have the "clustering features" in tandem. For all those, make them part of same cluster. For all others, clump them in a separate cluster.