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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews