Skip to main content

Phoenix Architecture

The underpinning philosophy

The entire backend stack is built on the Lagom framework, an open source framework for reactive Java and Scala microservices. The sale pitch for Lagom is that it allows developers to write robust microservices that can easily scale across large deployments. Lagom is a CQRS/ES framework and follows the reactive manifesto, which is to say that microservices should be

  • Responsive (Repond quickly)
  • Resilient (tolerates errors)
  • Elastic (Effortless scaling)
  • Message-driven (asynchronous messaging between services)

For more information on the reactive manifesto please read https://www.reactivemanifesto.org/ . It is short and highly informative.

Lagom documentation is also a required read for backend engineers.

The reactive manifesto is not a technology or a framework, it is simply a description for a technology that enables you to build software using the 4 principles mentioned above. And this is where Lagom comes in.

Additional resources can be found here which also discusses CQRS and ES which is what Lagom uses.

Why Lagom

We will break these down further but the high level reasons are as follows.

  • Scalability
  • Speed
  • Event Sourced
    • Auditability
    • Accurate data analysis

Scalability and Speed

Lagom and Akka(The actor pattern lagom uses) allows us to scale to tens of thousands of requests per second on a single machine, but even at scale the CPU begins to hit a limit with Thread Context Switching and Blocking I/O. Lagom minimizes these bottlenecks by eliminating cross-thread data sharing. And even when cpu limits start being reached it is trivial to spread the load across multiple cpu's and even machines because of Akkas model of concurrency

Event Sourcing

Event sourcing is a design pattern where we store a sequence of every state changing event in the system. The current state of the system can be reconstructed by replaying its events. This allows for some incredible benefits to the business.

  • 100% accurate audit log
  • Reporting and data analysis: Often reporting and some data analysis features are added as an after thought but with event sourcing this allows us to go back in time and pull accurate reports and information.

Cons and Trade-offs

With any technology there are going to be trade-offs.

  • Distributed computing is more complex than traditional monolith applications.
  • Lagom requires greater understanding of concurrent data sharing as well as additional technologies such as Kafka/Cassandra
  • Steep learning curve for people not familiar with Event Sourcing and CQRS

Working with our backend services

After reading through the Lagom documentation and Martin Fowlers article on Event sourcing you should have at least an understanding of the principles behind CQRS/ES. You can then dive into the services section.