concept OTP in category elixir

appears as: OTP
The Little Elixir & OTP Guidebook

This is an excerpt from Manning's book The Little Elixir & OTP Guidebook.

Everything seems OK for a while, but that’s just the calm before the storm. Eventually, users experience the same issues again, plus they see error messages, mysterious deadlocks occur, and other weird issues appear. In the end, you give up and write a long blog post about how your startup failed and why you should have built the application in Node.js or Golang. The post is #1 on Hacker News for a month. You then stumble upon OTP and learn that Elixir combined with OTP can be used to build concurrent, scalable, fault-tolerant, distributed programs.

Although this book won’t explain how to get venture capital, it will show you how to build a weather service using OTP, among other fun things. The OTP framework is what gives BEAM languages (Erlang, Elixir, and so on) their superpowers, and it comes bundled with Elixir.

One of the most important concepts in OTP is the notion of behaviors. A behavior can be thought of as a contract between you and OTP.

When you use a behavior, OTP expects you to fill in certain functions. In exchange for that, OTP takes care of a slew of issues such as message handling (synchronous or asynchronous), concurrency errors (deadlocks and race conditions), fault tolerance, and failure handling. These issues are general—almost every respectable client/server program has to handle them somehow, but OTP steps in and handles all of these for you. Furthermore, these generic bits have been used in production and battle-tested for years.

In this chapter, you begin by learning about OTP. OTP originally stood for Open Telecom Platform and was coined by the marketing geniuses over at Ericsson (I hope they don’t read this!). It’s now only referred to by its acronym. Part of the reason is that the naming is myopic—the tools provided by OTP are in no way specific to the telecommunications domain. Nonetheless, the name has stuck, for better or worse. (Naming is said to be one of the most difficult problems in computer science.)

In this chapter, you’ll learn exactly what OTP is. Then we’ll look at some of the motivations that drove its creation. You’ll also see how OTP behaviors can help you build applications that reduce boilerplate code, drastically reduce potential concurrency bugs, and take advantage of code that has benefited from decades of hard-earned experience.

Once you understand the core principles of OTP, you’ll learn about one of the most important and common OTP behaviors: GenServer. Short for Generic Server, the GenServer behavior is an abstraction of client/server functionality. You’ll take Metex, the temperature-reporting application that you built in chapter 3, and turn it into a GenServer. By then, you’ll have a firm grasp of how to implement your own GenServers.

4.1. What is OTP?

OTP is sometimes referred to as a framework, but that doesn’t give it due credit. Instead, think of OTP as a complete development environment for concurrent programming. To prove my point, here’s a non-exhaustive laundry list of the features that come with OTP: