Scaling horizontally with Docker replicas
So far, you have learned how to build a Producer/Consumer architecture with the Gin framework and RabbitMQ. In this section, we'll cover how to scale the consumer component so that we can split the incoming workload across multiple consumers.
You can achieve this by building a Docker image of the consumer project and building multiple containers based on that image. The Docker image is immutable, which guarantees the same environment each time a container is based on the image that is run.
The following schema illustrates how multiple consumers/workers are used:
To create a Docker image, we need to define a Dockerfile
– a blueprint that contains all the instructions to run the consumer project. Create a Dockerfile
in your worker/consumer directory with the following content:
FROM golang:1.16 WORKDIR /go/src/github.com/worker COPY main.go...