Building a chat app like whatsapp, messenger


I’ve built an application in Phoenix/Elixir which is more like a real-time polling application (like a big chat room). I’m currently exploring the option of building a chat application using Phoenix/Elixir. I went through different threads of Elixir forum in order to understand how I can achieve the same. I found this reply from Chris where he mentions keeping two channels. I’ve also gone through this thread where the end solution seemed to be Contus Fly.

Well I have gone ahead with Chris’s idea and also written some code but I was stuck with the problem of delivering offline messages. I’m thinking of storing all the topics for which the user has subscribed and when the user comes online I can push all the stored messages in different topics to the client (while also sending push notifications for the messages as and when they arrive on the server). But I’m confused where to store the messages till it has been successfully received by the client. Will it be a good idea to store the messages in a central database (Redis/Mongo) or somewhere else. I’m looking for a store-and-forward solution here.


1 Like

But I’m confused where to store the messages till it has been successfully received by the client.

In a voice messaging app I store (encrypted by the sender) messages that haven’t been delivered in a database.

1 Like

MongooseIM (a fork of ejabberd - the xmpp server Whatsapp started with) also stores undelivered messages in a database until they are delivered. What would be the alternative you are thinking of?

I stumbled upon this video where several use cases are mentioned for storing offline messages which led to my confusion. I was thinking of may be using a queue here. That way I can have some retry mechanism for sending the messages until I don’t get an ACK from the client. This way I can achieve more reliable message delivery in case of both online and offline clients.

I think the main cases of the slide are:

  • there is a session for the destinatary: (i) keep the message in memory; try to deliver it; and delete it once an ack is received. (ii) additionally persist all unacked messages when the session ends.

  • there is no session for the destinatary: persist all messages; try to deliver them upon the next session and delete them once acked.

Ill give Peculiar solution for your problem. It is the 2 best way to store & retrieve messages in Database.

Server-side database:

where the messages sent are stored in the server database. This results in the storage of a vast amount of data in the server-side data storage. ex : (Slack Hipchat)

On the other hand,

Client-side database :

It is quite effective in minimizing the data stored in the database by holding the data within the device & diminishing the queuing of messages and consumption of data. ex: (Whatsapp, Viber)


Server Side Database: Mysql,PosygreSQL.RIAK
Client-side Database : Android -> sqllite, iOS -> Realm DB , Web -> No database

P.S: I am Erlang developer in Mirrorfly. My colleague wrote this blog. Check this as reference

1 Like