Invoking Our Workers

Let’s learn about the role of workers in our project.

What are workers?

The workers are the different processes in our component. Generally, we’ll start with a flat design having a single worker and decide where we need to be more sophisticated. As our design evolves, we will see places where we need to add workers to clean up lifecycles or for concurrently dividing work. The following could potentially be workers in our Elixir project:

  • Connection pools

  • Tasks

  • Agents

Workers in the counter

Our counter component is not the simplest possible component. We could have a library with a counter API but no state at all. That program would not have any workers. Our counter, however, has a single worker—one we use to encapsulate state with OTP.

Partitioning workers

We also have to consider how to partition workers. Sometimes, we’ll want to start a process per user, such as web requests. Other times, we’ll have a consistent pool of processes to serve requests, such as a database connection pool. Right now, we don’t have to consider how to partition work efficiently, but keep in mind that Elixir can provide us with some of the best tools in the world for dealing with these kinds of issues.


Get hands-on with 1200+ tech skills courses.