pythondockermicroservicesdocker-swarmuwsgi

How to scale the service better: Docker swarm service replication or use uvicorn workers


Colleagues, hello everyone!

I have a large web application on a microservice architecture. The entire infrastructure works in Docker Swarm.

All microservices are worked to Python and run on a uvicorn server.

Uwsgi has its own workers which can be scaled.

In Docker Swarm, you can also scale the application by increasing the replicas of the service.

The question is how to scale the service better:

1) 1 docker swarm replicator - 100 (any other number) uvicorn workers

2) 100 (any other number) replicas of docker swarm - 1 uvicorn worker

3) 10 replicas of docker swarm - 10 uvicorn workers


Solution

  • It depends on your application and your requirements/capabilities, so it's hard to say exact answer. The Docker replicas and Uvicorn workers are on different levels in the micro-service architecture.

    The Docker handles the traffic (load) between the replicas and inside the replicas (containers) the Uvicorn handles the processes/requests between the workers.

    Replica and Unicorn architecture (very high level):

    Replicas and Uvicorn workers

    1. 1 docker swarm replicator - 100 (any other number) uvicorn workers
    1. 100 (any other number) replicas of docker swarm - 1 uvicorn worker
    1. 10 replicas of docker swarm - 10 uvicorn workers