Phoenix sockets as a service - best approach

I have a PHP app and I need to add a chat to it.
I already did one approach where I use Phoenix as an API and I send via PHP API calls in order for Phoenix to broadcast messages to the socket.

So the user types a message, hits enter, I save it to the DB via PHP, and then send the API call to Phoenix to broadcast that message to all connected users.
In this approach Phoenix has no connection to my database at all. It only broadcast messages. Kind of like the service offers.

The other approach is to let Phoenix to connect to my DB and control the whole socket.

My question is, how much different the performance will be?

1 Like

I guess it wouldn’t be much different, probably it would be a bit faster since less api calls are made.

A little off-topic, I would put both php and elixir/phoenix apps behind nginx and let the phoenix app handle request to /chat and websockets.


I’d guess running phoenix behind cowboy would be more than sufficient for prod load. Pretty heavy duty and reliable compared with nginx.


I just suggested nginx to be used as a reverse proxy.

But yes, I believe you are right that cowboy is enough for most cases.


Yup. Nginx is a perfect candidate as a reverse proxy. :blush: