Chapter 6
Distributed Elixir

Most programmers think of distributed systems as black magic, at once mysterious, valuable, and extraordinarily sensitive. They’re not far from wrong, but nearly all systems have distributed elements—every mobile application that reaches a server to exchange information, a load balanced web server, each new car navigation system that is part of a network, an application that communicates with a database, even simple web servers that connect to a social network for authentication. As programming requirements change, languages have to change with them.

The fact of the matter is that distributed systems are hard. Elixir doesn’t make them easy. It merely tries to make things a bit easier by offering tools, abstractions, and guarantees in the form of messages, nodes, and more. They help greatly when you do the difficult work of reasoning through the inevitable design constraints.

Take a simple database such as PostgreSQL. You might reach for it by default, but that choice brings assumptions. When you adopt your database as your sole source of truth, your choice impacts your response times. Every time you need new information from the database, your request will go over the network, and that takes time. Your database can also become a bottleneck (although a database used correctly will perform quite well despite popular folklore).

More to the point, if the database goes offline, in the best-case scenario it will be unable to accept writes or even be completely unusable. That’s the crux of distributed systems design. Communication between working nodes is only a small part of the problem. It’s usually availability and resilience rather than performance that drive us to distributed systems. Handling the unexpected is the heart of excellent distributed systems design. In essence, you need to get comfortable entertaining the question “What happens if I kill this?”

Rather than give you incomplete chapters that deliver a poor attempt at a complete anthology of distributed systems, we’ll explore Elixir’s constructs for distribution and how to leverage them for building systems you wouldn’t have considered otherwise. Like the other chapters in this book, this one will help you put core concepts in place and tell you where to find more. Then, when the time comes, you’ll be ready to go in depth on your own.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset