Chapter 4. OTP applications and supervision
This chapter covers
- An introduction to OTP applications
- Fault tolerance with OTP supervisors
- Generating documentation with EDoc
The entire purpose of the Erlang/OTP ecosystem is building stable, fault-tolerant systems. We introduced the core concepts of this ecosystem in chapter 3, building a simple RPC server; we now take it further and teach you how to pack this up properly and make it a fault-tolerant, production-quality service. We do this by introducing two new fundamental concepts:
- Applications are the way you package related modules in Erlang. The focus here isn’t on packaging for distribution but on being able to treat a bunch of modules as a single entity. Although OTP applications can be merely some library code for others to call, more often they’re like creatures with a life of their own: they start up, do what they’re designed to do, and shut down. Some can have multiple running instances, and some are limited to one instance at a time.
- Supervisors are one of the most important features of OTP. They monitor other processes and take action if anything goes wrong, restarting the failed process or possibly escalating the problem to a higher level. Layering supervisors into supervision trees allows you to create highly fault-tolerant systems.