๐Ÿคน Balancer

Distributing traffic among multiple instances of a microservice is an important technique to ensure service reliability. NATS allows us to easily group instances of a microservice and ensure an even distribution of incoming traffic.

By creating an App class with a allocation_queue_group argument upon initialization, all microservices within the group will receive messages in an even distribution. This can be done with the following code:

from panini import app as panini_app

app = panini_app.App(
    service_name="async_publish",
    host="127.0.0.1",
    port=4222,
    allocation_queue_group='unit1'
)

The example above creates a microservice insance in the unit1 group. This ensures that any incoming traffic will be distributed evenly among the microservices within the group.

Here's a diagram that further illustrates the process:

screenshot

By creating an App class with a allocation_queue_group argument, it's easy to ensure an even distribution of incoming traffic among microservices. This will help make sure that services stay reliable and can scale to handle more traffic.