Starting Per-User Processes with a Dynamic Supervisor
Explore how to start and manage processes for each user using dynamic supervisors in Elixir. Understand defining child specs, handling process lifecycles, and controlling restarts to build robust, scalable systems.
Now we need to start a process per user. There are two reasons for doing this:
-
We don’t have a fixed number of processes to start.
-
We’ll also need to be able to look them up based on a user’s attributes.
Hence, we will need a structure that is a little more sophisticated. We will use a dynamic supervisor.
Properties and requirements of dynamic supervisors
Most supervisors create processes when an application starts or restarts. That’s typically what you want, but not always. A dynamic supervisor is a supervisor that starts children dynamically. Since we have no way of knowing who will take quizzes and when, that sounds like exactly ...