elie

elie

Real time PostgreSQL and Phoenix

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?

Marked As Solved

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.

Also Liked

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

elie

elie

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?

Last Post!

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

Where Next?

Popular in Questions Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement