axon

QueryHandler load balancing when scaling app


When I'm scaling my application that handles queries I'd expect the multiple instances to get a somewhat load balanced amount of request. But all queries end up on one instance:

Queries handler

There are multiple external services firing these queries using a QueryGateway. What I'm want is async request/reply services that are able to distribute load when many requests are send. Is this not the usecase for QueryGateways?

Given this QueryHandler in a spring boot application:

@Component
public class CalculateProfanityScoreQueryHandler {

  @QueryHandler
  public CompletableFuture<ProfanityScore> handle(CalculateProfanityScoreQuery query) {
    int score = rateComment();
    ProfanityScore profanityScore = new ProfanityScore(score);
    return CompletableFuture.completedFuture(profanityScore);
  }
}

And external services connected to the same Axon Server instance making requests like this:

 @Override
  public ProfanityEvaluation calculateScore(String comment) {
    var profanityScore =
        queryGateway
            .query(
                new CalculateProfanityScoreQuery(comment),
                ResponseTypes.instanceOf(ProfanityScore.class))
            .get();

    // rest of logic
  }

Overview in Axon dashboard for given service scaled to 6 instances: enter image description here


Solution

  • It's working as expected with axonserver 2024.0 and 2023.1.2-dev (i'm using SE versions). It's broken in all 2023.2.x versions. It will only use the first query handler instance (sorted alphabetically by Instance Name).