The GenServer Pattern

Learn the pattern for our GenServer.

Parts of a GenServer

There’s a simple pattern at the heart of every bit of functionality we build in a GenServer. It has three moving parts:

  • A client function
  • A function from the GenServer module
  • A callback

The client function is the public interface, the part that other processes will call. Within the client function, we call a GenServer module function that does some internal work before it triggers a callback. The callback is where we do the real work and return a response. Here is the pattern of the GenServer module:

Get hands-on with 1200+ tech skills courses.