Teamgenik is made with Elixir and Phoenix LiveView
Programming language Elixir
Teamgenik's core system is written in Elixir, a functional programming language.
Elixir is a new language born in 2012. Compared to C born in 1972, Python born in 1991, Java born in 1995, Ruby, etc., it is not yet known, but it is gaining popularity in the field of Web and IoT. InfoQ's Programming Languages InfoQ Trends Report, released in October 2019, says Elixir has entered the innovator phase.
Teamgenik uses the Phoenix Framework (Phoenix), an Elixir-based web application development framework.
Phoenix is heavily influenced by Ruby on Rails. In particular, the routing and controller mechanisms are very similar. The library Ecto that Phoenix uses for database operations is similar to Active Record. For those of us familiar with Ruby on Rails, Phoenix was a very natural choice.
Teamgenik uses Phoenix LiveView to render HTML code. PhoenixLiveView generates HTML code in two steps:
- In response to events that occur outside the app, the app's state is converted to a new state.
- Detects changes in state and generates HTML code.
Phoenix LiveView provides a constant connection between the browser and the server via WebSocket.
Phoenix LiveView sends only the difference generated in the HTML code due to the change in state to the browser, so the amount of communication between the browser and the server can be kept low.
New trends in single page application (SPA) development
Teamgenik is built as a single page application (SPA). In other words, instead of causing a screen transition each time a user clicks a link, a part of the screen is changed on the spot.
However, we adopted Phoenix LiveView in anticipation of the trend since the 2020s. SPA development with PhoenixLiveView is very different from the previous one in that it is server side centered.
There are four main reasons that the focus of development has shifted from the front end (browser side) to the server side:
- It is not necessary to implement an API that receives inquiries from the front end.
- It is no longer necessary to create the same type of functions (validation etc.) on the front end and server side.
Of course, there are things that you lose. Moving some of the processing that was done on the user's computer to the server side means increasing the burden on the server. It also increases the amount of communication that occurs between the front end and the server side. Also, if the browser and server are separated by a network, users may feel more responsive.
We believe that these shortcomings will be overcome as the development and acceptance of Phoenix LiveView progresses. After all, version 0.1 was just released in August 2019 and has not yet reached version 1.0.
LiveView Socket has a one-to-one correspondence with browsers
In traditional web systems, a small number of web applications respond to access from a very large number of browsers (see below).
One Web application processes requests from multiple browsers in order. Also, it is not constant which Web application is responsible for requests from a certain browser. As a result, Web applications cannot hold specific browser-specific data. The data is stored in the database or in the State on the browser.
On the other hand, in the system using LiveView, LiveView Socket has a one-to-one correspondence with the browser as shown in the following figure. Both are always connected via WebSocket.
Each LiveView Socket is so small that it can continue to run thousands or even tens of thousands on a single server. And each LiveView Socket has a unique State.
In this way, using Phoenix LiveView fundamentally changes the way web systems are created.
What is LiveView Socket?
All programs written in the programming language Elixir run on a virtual machine (VM) named BEAM. A program that is running is called a process. To distinguish it from OS-level processes, processes on BEAM are sometimes called Erlang processes or Erlang lightweight processes. This is because BEAM was originally created for the programming language Erlang.
An Elixir process can spawn another process. All processes are isolated from each other and communicate with each other through message passing.
In the Web system using Phoenix LiveView, a dedicated process is created each time a connection request is received from a new browser. This is LiveView Socket. This process continues to run until the browser disconnects.