Designing Elixir Systems With OTP

Book description

You know how to code in Elixir; now learn to think in it. Learn to design libraries with intelligent layers that shape the right data structures, flow from one function into the next, and present the right APIs. Embrace the same OTP that's kept our telephone systems reliable and fast for over 30 years. Move beyond understanding the OTP functions to knowing what's happening under the hood, and why that matters. Using that knowledge, instinctively know how to design systems that deliver fast and resilient services to your users, all with an Elixir focus.

Elixir is gaining mindshare as the programming language you can use to keep you software running forever, even in the face of unexpected errors and an ever growing need to use more processors. This power comes from an effective programming language, an excellent foundation for concurrency and its inheritance of a battle-tested framework called the OTP.

If you're using frameworks like Phoenix or Nerves, you're already experiencing the features that make Elixir an excellent language for today's demands. This book shows you how to go beyond simple programming to designing, and that means building the right layers. Embrace those data structures that work best in functional programs and use them to build functions that perform and compose well, layer by layer, across processes. Test your code at the right place using the right techniques. Layer your code into pieces that are easy to understand and heal themselves when errors strike.

Of all Elixir's boons, the most important one is that it guides us to design our programs in a way to most benefit from the architecture that they run on. The experts do it and now you can learn to design programs that do the same.

What You Need:

Elixir Version 1.7 or greater.

Publisher resources

View/Submit Errata

Table of contents

  1.   Acknowledgments
    1. James Gray
    2. Bruce Tate
  2.   Introduction
    1. Worker-Bee-Driven Design
    2. Who Should Read This Book
    3. Online Resources
  3. 1. Build Your Project in Layers
    1. We Must Reimagine Design Choices
    2. Choose Your Layers
    3. Begin with the Right Datatypes
    4. Build Your Functional Core
    5. Establish Your Boundaries
    6. Test Your Code
    7. Plan Your Lifecycle
    8. Invoke Your Workers
    9. Do Fun Things with Big, Loud Worker-Bees
  4. Part I. Do Fun Things...
    1. 2. Know Your Elixir Datatypes
      1. Primitive Types
      2. Lists
      3. Maps and Structs
      4. Strings
      5. Tuples
      6. Functions as Data
      7. When to Leave Elixir
      8. Know Your Elixir Datatypes
    2. 3. Start with the Right Data Layer
      1. Access Patterns Shape Data Structures
      2. Immutability Drives Everything
      3. Try It Out
      4. Start with the Right Data
    3. 4. Build a Functional Core
      1. Organize Core Functions by Purpose
      2. Compose a Quiz from Functions
      3. Build at a Single Level of Abstraction
      4. Keep the Left Margin Skinny
      5. Try Out the Core
      6. Build Your Functional Core
    4. 5. Test Your Core
      1. Simplify Tests with Common Setup Functions
      2. Improve the ExUnit Infrastructure
      3. Provide Test Data with Fixtures
      4. Prime Tests with Named Setups
      5. Make Tests Repeatable
      6. Compose Within Tests
      7. Take Tests Beyond the Elixir Base
      8. Test Your Functional Core
  5. Part II. ...with Big, Loud Worker-Bees
    1. 6. Isolate Process Machinery in a Boundary
      1. Maintain Composition Through Uncertainty
      2. Build Your Optional Server
      3. Wrap the Server in an API
      4. Prefer Call Over Cast to Provide Back Pressure
      5. Extend Your APIs Safely
      6. Wrap Your Core in a Boundary API
    2. 7. Customize Your Lifecycle
      1. Understand the Lifecycle Building Blocks
      2. Configure Applications to Start Supervisors
      3. Start Per-User Processes with a Dynamic Supervisor
      4. Touch Up the API Layer
      5. Manage Your Lifecycles with Supervisors
    3. 8. Summon Your Workers
      1. Know Your Motivations
      2. Know Your Tools
      3. Add a Proctor to Run Timed Quizzes
      4. Summon Your Workers
    4. 9. Assemble Your Components
      1. Add Persistence as a Boundary Service
      2. Integrate MasteryPersistence into Mastery
      3. Integrate Your OTP Dependencies into Phoenix
      4. Organize Code for OTP Abstractions
      5. Build Scenic Projects with Layers
      6. Assemble Your Components
    5. 10. Test the Boundary
      1. Tests Call the API as a User Would
      2. Isolate the Proctor’s Boundary Concerns
      3. Test Your Boundary
  6.  Bibliography

Product information

  • Title: Designing Elixir Systems With OTP
  • Author(s): James Edward Gray, Bruce A. Tate
  • Release date: December 2019
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680507379