Use Phoenix LiveView to Enhance Observability

Application observability is becoming more and more important nowadays. Phoenix LiveView is a perfect technical solution for this use case. In this post, we will see how important observability is and why Phoenix LiveView is a perfect fit.

Application Observability is More Important Than Ever

On the business side, decision makers are asking for some kinds of Operational Intelligence. In an episode of the a16z Podcast, they discussed The Future Of Decision-Making. They noticed that:

As companies digitize, they change the way they make decisions: decisions are made lower in the organization, based on data, and increasingly automated.

In another word, our application needs to provide real-time business related data, such as subscription numbers, churn rate, and so on. Since the data is updated in real-time, business people don't have to wait for a long feedback cycle (from weeks to years) to get a conclusion and then make a decision.

On the operation side, DevOps people are asking for the same thing, a better Operator Experience. In Operable Software, Fred Hebert explained why Observability is important:

  • If we want our system to be reliable, we need to know when it misbehaves and when there are bugs.
  • The general approach for this is monitoring
    • In a nutshell, monitoring is the act of asking your system "how are you doing?", and checking for a response
    • Monitoring generally tells you only whether something is wrong, but not what is wrong, nor why it is wrong.
  • The identification of a fault is more generally resolved through observability.
    • monitoring asks "how are you doing?"
    • observability asks "what are you doing?"
  • Observability comes from control theory
    • self-regulating systems such as
      • speed control on a car,
      • flight stabilizers in airplanes.
    • The gist of observability according to control theory is that by looking at the outputs of a system, you can infer its internal state.

To get a higher level of observability, our application needs to provide real-time data to infer its internal state. Again, real-time is the key here. Only with a short feedback loop, can a better Operator Experience be achieved.

The demands are high from both the business perspective and operation perspective. But I don't see any good solutions for this problem. That's also why in The Future Of Decision-Making, the hosts thought this problem is a great opportunity for starting a new business.

Phoenix LiveView Comes to the Rescue

In this episode of Elixir Mix Podcast, the hosts discussed LiveView with Leandro Pereira. And Leandro mentioned:

LiveView is a great technical solution for building business intelligence dashboard.

You may ask Why. I think the answer is obvious here: Phoenix LiveView was born for providing real-time data. Its GitHub project description says:

phoenixframework/phoenix_live_view: Rich, real-time user experiences with server-rendered HTML

To be more specific, Phoenix LiveView is so backend-friendly that showing real-time data is just an ease.

Calculating real-time data is mostly a backend work. Phoenix LiveView empowers a backend developer to write a highly interactive frontend without writing a single line of JavaScript.

Like what I did for a Sudoku solver:

Updating data in real-time is just a few lines of code:

def handle_info(:update, socket) do
  {new_sudoku, pos} = Sudoku.next(socket.assigns.server)

  Process.send_after(self(), :update, socket.assigns.interval)

  {:noreply, assign(socket, sudoku: new_sudoku, highlight_pos: pos)}
end

Another real-world example is the Observer Live interface made by Dimitris Zorbas.

This is what the better Operator Experience looks like in real-life. And you can imagine the power it would bring to the business people if it's showing business critical data in real-time.

To me, it's a no-brainer to use LiveView for adding this kind of feature to an existing Phoenix app. If it's not a Phoenix app, you may need to build a new service for it and balance the trade-offs of bringing a new language/framework to your team. But I think it would be worth it. Let me know what you think about it!