In chapter 5, you became familiar with basic concurrency techniques: you learned how to create processes and communicate with them. I also explained the idea behind stateful server processes—long-running processes that react to messages and maintain state.
Server processes play an important role and are used frequently when building highly concurrent systems in Elixir and Erlang, so we’ll spend some time exploring them in detail. In this chapter, you’ll learn how to reduce some of the boilerplate associated with server processes, such as infinite recursion, state management, and message passing.
Erlang provides a helper module for implementing server processes—it’s part of the Open Telecom Platform (OTP) framework. Despite its misleading name, the framework has nothing to do with telecoms; rather, it provides patterns and abstractions for tasks such as creating components, building releases, developing server processes, handling and recovering from runtime errors, logging, event handling, and upgrading code.
You’ll learn about various parts of OTP throughout this book, but in this chapter, we’ll focus on one of its most important parts: GenServer, the module that simplifies the implementation of server processes. Before we look at GenServer, though, you’ll implement a simplified version of it, based on the message-passing primitives you saw in chapter 5.