Open Telecom Platform (OTP)

One of the most important abstractions for both the Elixir and Erlang ecosystems is called OTP, and the heart of OTP is the generic server. It’s an abstraction that we’ll use to wrap up critical features as application services, represent state using processes, and use built-in supervision to make those features reliable. As we’ve seen earlier, Elixir leans heavily on processes to make the notions of state, behavior, and time explicit. In this lesson, we’ll focus on OTP—a critical abstraction providing common services many processes need, such as supervision.

In the following lessons, we want to shine a light on GenServer and discuss cases of use and misuse, relaying some stories from the field and the greater Elixir community. To do so, we’ll walk through enough foundational concepts to appreciate the nuanced conclusions that follow.

The GenServer’s Story

We’re going to build the intuition for a generic server from the ground up.

The essence of OTP is not complex, but it is important. We’ll need these concepts to make our way through this course and throughout an Elixir programming career. When we’re done with this lesson, we’ll understand how to use recursion, concurrency, and supervision to build lightweight services that do all kinds of things.

The counter example

Take this very simple counter. It receives messages to increment its state and allows other processes to request its value, like this:

Get hands-on with 1200+ tech skills courses.