0% found this document useful (0 votes)
38 views29 pages

Elixir Reactive App

The document discusses building concurrent and reactive web applications using Elixir. It provides an overview of Elixir's design goals including concurrency, productivity, and maintainability. It then presents a sample trivia game web application and discusses the concurrency issues that can arise when building such an app using traditional object-oriented programming approaches. The document proceeds to explain how Elixir and its BEAM virtual machine, along with features like processes, allow building the app in a way that avoids these issues. It outlines the app's structure and components when built with Phoenix, the Elixir web framework, concluding that Elixir and Phoenix enable fast and productive development of concurrent web applications.

Uploaded by

white rabbit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views29 pages

Elixir Reactive App

The document discusses building concurrent and reactive web applications using Elixir. It provides an overview of Elixir's design goals including concurrency, productivity, and maintainability. It then presents a sample trivia game web application and discusses the concurrency issues that can arise when building such an app using traditional object-oriented programming approaches. The document proceeds to explain how Elixir and its BEAM virtual machine, along with features like processes, allow building the app in a way that avoids these issues. It outlines the app's structure and components when built with Phoenix, the Elixir web framework, concluding that Elixir and Phoenix enable fast and productive development of concurrent web applications.

Uploaded by

white rabbit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 29

A taste of elixir:

Building concurrent and


reactive web applications

Ruben Amortegui
@ramortegui
https://github.com/ramortegui
What’s Elixir
● Functional Programming Language
● Runs on the Erlang Virtual Machine

Design Goals: Updated Goals(2017)


● Compatibility ● Productivity

● Productivity ● Maintainability

● Extensibility ● Reliability

https://elixir-lang.org/blog/2013/08/08/elixir-design-goals/
Sample Web App
● Trivia Game
– Multi-Player
– Questions come from external service
– Players can create a trivia game
– Players can join a trivia game
– Game timed
– “Real-time” updates
https://en.wikipedia.org/wiki/Trivia
How to create a trivia app in OOP?
Concurrency Issues
● Race conditions
– Lost updates, access to out-of-date data, etc.
● Workarounds:
– Confinement.
– Immutability.
– Threadsafe data type.
– Synchronization.

http://web.mit.edu/6.005/www/fa15/classes/20-thread-safety/
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0005267.html
Erlang/OTP

● Complete development environment for


concurrent programming.
● takes advantage of all the ecosystem.
BEAM

https://freecontent.manning.com/dipping-your-toes-into-elixir/
Processes

https://elixir-lang.org/getting-started/processes.html
● MVC
● Productive, Reliable, and Fast.
Creating an app

>mix phx.new trivia --no-ecto


Phoenix app Structure
Data Structures

● Trivia.Player
● Trivia.Question
● Trivia.Game
● Trivia.GameServer
● Trivia.DynamicSupervisor
Trivia.Player
Player.Question
Trivia.Game
Trivia.GameServer
Trivia.GameServer 2
Trivia.GameServer 3
Trivia.DynamicSupervisor
Phoenix Live View
● Phoenix LiveView enables rich, real-time user
experiences with server-rendered HTML.

https://elixirschool.com/blog/phoenix-live-view/
Config Live View
● Add LiveView dependency
● Setup configuration (add signing salt)
● Import functions into the web context
● Enable the socket to connect using the /live
route.
● Add Phoenix Live View javascript package as
dependency.
https://github.com/ramortegui/phoenix_trivia/commit/bc1bae7d32a24a51ca510e2ee3b2971d3c8b2735
TriviaWeb.Live.TriviaView
TriviaWeb.Live.TriviaView
Trivia Live View Template
Trivia Live View Template
https://phx-trivia.gigalixirapp.com
Summary
● Elixir and Phoenix provide an ecosystem to
develop applications with concurrency in mind.
● You don’t need to choose between fast and
productive when you are going to develop a
web application, you could have both.
Q & A?

https://www.meetup.com/Elixir-Calgary/

Thanks!

@ramortegui
https://github.com/ramortegui

You might also like