small medium large xlarge

Functional Web Development with Elixir, OTP, and Phoenix: Rethink the Modern Web App


Cover image for Functional Web Development with Elixir, OTP, and Phoenix

Functional Web Development with Elixir, OTP, and Phoenix

Rethink the Modern Web App


Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web applications. For decades OTP has helped developers create incredibly robust, scalable applications with unparalleled uptime. Make the most of them as you build a stateful web app with Elixir, OTP, and Phoenix. Model domain entities without an ORM or a database. Manage server state and keep your code clean with OTP Behaviours. Layer on a Phoenix web interface without coupling it to the business logic. Open doors to powerful new techniques that will get you thinking about web development in fundamentally new ways.

Choose Your Format(s)

  • $24.95 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

  • The Paper Book will ship on 2018-02-10 (roughly).

About this Title

Pages: 250 (est)
Published: 2018-02-10
Release: B7.0 (2017-11-16)
ISBN: 978-1-68050-243-5

Elixir and OTP provide exceptional tools to build rock-solid back-end applications that scale. In this book, you’ll build a web application in a radically different way, with a back end that holds application state. You’ll use persistent Phoenix Channel connections instead of HTTP’s request-response, and create the full application in distinct, decoupled layers.

In Part 1, start by building the business logic as a separate application, without Phoenix. Model the application domain with Elixir Agents and simple data structures. By keeping state in memory instead of a database, you can reduce latency and simplify your code. Then add OTP Behaviours such as gen_server and gen_statem that make managing in-memory state a breeze. Create a supervision tree to boost fault tolerance while separating error handling from business logic.

Phoenix is a modern web framework you can layer on top of business logic while keeping the two completely decoupled. In Part 2, you’ll do exactly that as you build a web interface with Phoenix. Bring in the application from Part 1 as a dependency to a new Phoenix project. Then use ultra-scalable Phoenix Channels to establish persistent connections between the stateful server and a stateful front-end client.

You’re going to love this way of building web apps!

What You Need

You’ll need a computer that can run Elixir version 1.3 or higher and Phoenix 1.2 or higher. Some familiarity with Elixir and Phoenix is recommended.

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

  • Build a Game Engine in Pure Elixir
    • Model State With Agents
      • Embracing Stateful Servers
      • Agents
      • Let’s Build It
      • Model A Simple Entity
      • Model a Relationship With a List
      • Model a Relationship With a Map
      • Model Relationships With a Struct
      • A Single Representation
      • Wrapping Up
    • Wrap It Up In a GenServer
      • Services, A Fuller Picture
      • OTP Solutions
      • Introducing OTP Behaviours
      • Getting Started With GenServer excerpt
      • Initializing GenServer State
      • Customizing GenServer Behavior
      • Pipelines to Handle Complexity
      • Naming GenServer Processes
      • Stopping GenServer Processes
      • Wrapping Up
    • Manage State with gen_statem
      • A Bit of History
      • State Machines and :gen_statem
      • Getting Started with :gen_statem
      • Adding New Behavior
      • Fully Customizing Our State Machine
      • Defining the Missing Behaviour Callbacks
      • Integrate the :gen_statem with the GenServer
      • Seeing the GenServer and :gen_statem in Action
      • Wrapping Up
    • Process Supervision For Recovery
  • Add a Web Interface With Phoenix
    • Generate a New Web Interface With Phoenix excerpt
      • Frameworks
      • OTP Applications
      • Generate a New Phoenix Application
      • Adding a New Dependency
      • Call the Logic from the Interface
      • Wrapping Up
    • Create Persistent Connections With Phoenix Channels
      • The Beauty of Channels
      • The Pieces That Make a Channel
      • Let’s Build It
      • Establish a Client Connection
      • Converse Over a Channel
      • Connect the Channel to the Game
      • Phoenix Presence
      • Authorization
      • Wrapping Up


Lance Halvorsen is a member of the Phoenix core team, the author of the Phoenix Guides, and a senior software architect at Le Tote.