small medium large xlarge

Programming Phoenix: Productive |> Reliable |> Fast


Cover image for Programming Phoenix

Programming Phoenix

Productive |> Reliable |> Fast


Don’t accept the compromise between fast and beautiful: you can have it all. Phoenix creator Chris McCord, Elixir creator José Valim, and award-winning author Bruce Tate walk you through building an application that’s fast and reliable. At every step, you’ll learn from the Phoenix creators not just what to do, but why. Packed with insider insights, this definitive guide will be your constant companion in your journey from Phoenix novice to expert, as you build the next generation of web applications.

Customer Reviews

Programming Phoenix is an excellent introduction to Phoenix. You are taken from
the basics to a full-blown application that covers the MVC layers, real-time clientserver
communication, and fault-tolerant reliance on 3rd party services. All tested,
and presented in a gradual and coherent way. You’ll be amazed at what you’ll be
able to build following this book.

- Xavier Noria

Rails Core Team

I write Elixir for a living, and Programming Phoenix was exactly what I needed. It
filled in the sticky details, like how to tie authentication into web applications and
channels. It also showed me how to layer services with OTP. The experience of
Chris and José makes all of the difference in the world.

- Eric Meadows-Jönsson

Elixir Core Team

A valuable introduction to the Phoenix framework. Many small details and tips
from the creators of the language and the framework, and a leader in using Phoenix
in production.

- Kosmas Chatzimichalis

Software Engineer, Mach7x

Programming Phoenix is mandatory reading for anyone looking to write web applications
in Elixir. Every few pages I found myself putting the book down so I could
immediately apply something I’d learned in my existing Phoenix applications.
More than merely teaching the mechanics of using the Phoenix framework, the
authors have done a fantastic job imparting the underlying philosophy behind it.

- Adam Kittelson

Principal Software Engineer, Brightcove

See All Reviews

About this Title

Pages: 298
Published: 2016-04-10
Release: P1.0 (2016-04-27)
ISBN: 978-1-68050-145-2

Phoenix is the long-awaited web framework based on Elixir, the highly concurrent language that combines a beautiful syntax with rich metaprogramming. The authors, who developed the earliest production Phoenix applications, will show you how to create code that’s easier to write, test, understand, and maintain.

The best way to learn Phoenix is to code, and you’ll get to attack some interesting problems. Start working with controllers, views, and templates within the first few pages. Build an in-memory repository, and then back it with an Ecto database layer. Learn to use change sets and constraints that keep readers informed and your database integrity intact. Craft your own interactive application based on the channels API for the real-time, high-performance applications that this ecosystem made famous. Write your own authentication components called plugs, and even learn to use the OTP layer for monitored, reliable services. Organize your code with umbrella projects so you can keep your applications modular and easy to maintain.

This is a book by developers and for developers, and we know how to help you ramp up quickly. Any book can tell you what to do. When you’ve finished this one, you’ll also know why to do it.

Q&A with José Valim, creator of Elixir, and Chris McCord, creator of Phoenix.

José Valim, creator of Elixir, and Chris McCord, creator of Phoenix collaborated with Bruce Tate on Programming Phoenix. They took some time out of their busy days to answer a few questions about those two important inventions.

Q: José, why did you create Elixir?

A: Elixir was created out of a need for writing robust and concurrent software productively. In the last decade, our CPUs are not getting any faster, instead we are getting computers with more and more cores. This change in hardware is affecting how we write software and Elixir reflects that.

Q: José, why did you choose the Erlang VM for Elixir?

A: The Erlang VM is one of the few runtimes widely deployed in production that was designed for running network services. The Erlang VM provides the foundation that allows Phoenix to be extremely performant while holding 2 million open connections on a single machine. Elixir adds productive and expressive tooling to this robust runtime.

Q: José, was Elixir designed solely for the web?

A: Elixir was designed to be an extensible language. Throughout the book, we will see how Phoenix and Ecto effectively extend Elixir to provide fast request routing, elegant database queries and more. However, they are two of many examples. As Elixir adoption increases, we will continue to see it being brought to new domains, like data processing and embedded software.

Q: Chris, why did you write Phoenix?

A: I wanted a Web framework that could take on the modern Web’s realtime requirements of many connected devices. I found Elixir and realized it would allow a framework to be both highly productive and have world-class performance. Thus Phoenix was born.

Q: Chris, why is it better than what you used before?

A: Web frameworks that I had used before gave me the productivity I wanted, but I had to sacrifice performance to get a system that was a joy to program in. At the same time, most languages and frameworks I had experience in scaled very poorly when handling long-running, persistent connections. With Phoenix, we can handle millions of active connections on a single server in a language that is such a joy to use.

Q: Chris, what kinds of apps can benefit?

A: Any application requiring persistent connections is an obvious benefactor, but even standard HTML5 or JSON API applications see huge benefits when using Phoenix. Programmers often see microsecond response times when using Phoenix for HTML or JSON applications, and this directly results in heightened end-user experiences. We cover both types of applications in Programming Phoenix.

What You Need

To work through this book, you will need a computer capable of running Erlang 17 or better, Elixir 1.1, or better, Phoenix 1.0 or better, and Ecto 1.0 or better. A rudimentary knowledge of Elixir is also highly recommended.

Contents & Extracts

  • Introduction
  • Building with Functional MVC
    • The Lay of the Land
      • Simple Functions
      • Installing Your Development Environment
      • Creating a Throwaway Project
      • Building a Feature excerpt
      • Going Deeper: The Request Pipeline
      • Wrapping Up
    • Controllers, Views, and Templates
      • The Controller
      • Creating Some Users
      • Building a Controller
      • Coding Views
      • Using Helpers
      • Showing a User
      • Wrapping Up
    • Ecto and Changesets
      • Understanding Ecto
      • Defining the User Schema and Migration
      • Using the Repository to Add Data
      • Building Forms
      • Creating Resources
      • Wrapping Up
    • Authenticating Users
      • Preparing for Authentication
      • Managing Registration Changesets
      • Creating Users
      • The Anatomy of a Plug excerpt
      • Writing an Authentication Plug
      • Implementing Login and Logout
      • Presenting User Account Links
      • Wrapping Up
    • Generators and Relationships
      • Using Generators
      • Building Relationships
      • Managing Related Data
      • Wrapping Up
    • Ecto Queries and Constraints excerpt
      • Adding Categories
      • Diving Deeper into Ecto Queries
      • Constraints
      • Wrapping Up
    • Testing MVC
      • Understanding ExUnit
      • Using Mix to Run Phoenix Tests
      • Integration Tests
      • Unit-Testing Plugs
      • Testing Views and Templates
      • Splitting Side Effects in Model Tests
      • Wrapping Up
  • Writing Interactive and Maintainable Applications
    • Watching Videos
      • Watching Videos
      • Adding JavaScript
      • Creating Slugs
      • Wrapping Up
    • Using Channels
      • The Channel
      • Phoenix Clients with ES6
      • Preparing Our Server for the Channel
      • Creating the Channel
      • Sending and Receiving Events
      • Socket Authentication
      • Persisting Annotations
      • Handling Disconnects
      • Wrapping Up
    • OTP
      • Managing State with Processes
      • Building GenServers for OTP
      • Supervision Strategies
      • Designing an Information System with OTP
      • Building the Wolfram Info System
      • Wrapping Up
    • Observer and Umbrellas
      • Introspecting with Observer
      • Using Umbrellas
      • Wrapping Up
    • Testing Channels and OTP
      • Testing the Information System
      • Isolating Wolfram
      • Adding Tests to Channels
      • Authenticating a Test Socket
      • Communicating with a Test Channel
      • Wrapping Up
    • What’s Next?
      • Other Interesting Features
      • What’s Coming Next
      • Good Luck


This is the team that drove the implementation of Elixir and Phoenix. Chris McCord, the creator of Phoenix, professionally trains new developers for the rising framework and works with teams adapting it. Bruce Tate, the author of many award-winning books and creator of the Seven Languages in Seven Weeks series, is the CTO for, which is already running Phoenix in production. José Valim, the creator of Elixir and member of the Phoenix core team, is the co-founder and director of research and development at Plataformatec.