elie

elie

Hi,

My first post here! I’m very new to Elixir and Phoenix (coming from the Meteor community).

I understand that Phoenix is great for real time apps (such as chat). Does the database need to be real time? How does Phoenix observe changes in real time to a PostgreSQL database (which I understand is the default for Phoenix apps)? And what sort of delay can you expect, if any?

Showing Posts 1 to 6

Qqwy

Qqwy

TypeCheck Core Team

Yes, Phoenix is great for applications where you want to use a persistent, two-way connection between server and client, where both the client and the server can keep sending updates to each other without needing to reconnect each time. This is what indeed enables ‘real time’ applications.

When building things like a chat application, each time someone posts a message, Phoenix will forward this message to all other open connections (that are part of the given context, i.e. chat room). The database is no part of this.

Because connections are persistent, Phoenix does not need to look at the database when a new request comes in. Instead, the database is only used to log what happened, so someone that connects at a later moment is able to see what took place.

So, because all of this is happening in memory, with the database being only an observer of the changes that happen, this kind of communication is ridiculously fast. What sort of delay you can expect is of course highly dependent on the needs of your specific application, but you might like to take a look at this benchmark, which shows that Phoenix can handle two million persistent connections on a single server with a non-trivial application without a problem.

elie

elie OP

So based on this, does it matter at all what sort of database you use with Elixir?

I’m also wondering, wouldn’t this mean that Elixir needs an enormous amount of RAM for large applications? It basically has to hold the entire database in memory in a lot of cases no?

OvermindDL1

OvermindDL1

No, as in your DB holds persistent data, but anything that needs to be broadcasted out to existingly connected users can be done so immediately, and when a new user connects you can send them what they are missing.

elie

elie OP

So would a real time database like RethinkDB add anything to an Elixir application?

Also, with the chat room example, let’s say we have 1000 chatrooms, would it be possible to have 2 Elixir instances each in charge of 500 rooms? And how does this sort of thing happen?

OvermindDL1

OvermindDL1

It can simplify some code but honestly not really.

Elixir/Erlang could handle a lot more than that in a single instance, but yes, Elixir/Erlang can distribute across a ‘mesh’ of nodes across computers to slave out work, and yes the Phoenix pubsub system supports it fantastically (built for it).

brightball

brightball

You can also do this with PG though even though you don’t need to for your use case. Postgres LISTEN/NOTIFY will allow outside processes like your elixir application to be notified when certain things happen in the database. I believe there is a library called Boltun that makes it pretty dang simple.

https://github.com/bitgamma/boltun

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews