What would be the best way to add chat feature to an android, ios, and web app? Is polling really as bad as people say?

The requirements are user to user messaging and chat rooms.

Here is my thought process:

  1. Long polling with in memory cache. The long polling endpoint will continually check the in memory cache. Pretty simple to implement.
  2. XMPP based server like OpenFire. Hard to horizontally scale. Some other implementations scale well but setup is more complex.
  3. Websocket with in memory cache. Pretty simple to implement.
  4. Short polling with reasonable delay, say every two seconds to ping the server. Query relational database. Store all chats in database. Have it designed so that if user doesn't do anything after 20 seconds, they get a prompt or we stop polling. This seems the simplest to implement.

I guess what I'm wondering is short polling really that bad. I am making a startup and don't want to make a mistake with investing time with a solution that isn't going to scale well.

At the same time, I am thinking that if I get funding / traction, then I can always invest into the more scalable solution.

If I don't make any money from it though, I don't want to invest time into the app.

Any thoughts?

  • I would think the mechanism depends on the each client's abilities. Push notifications for mobile? Websockets for web -- and possibly mobile (when the app is in the foreground). Long polling as a fallback for web? "Regular" sockets for desktop? It may be more complicated at first, but I would try to separate sending from delivery -- and from initial loading of past/historical messages. – svidgen Mar 21 '18 at 4:43

I have used all the options you have provided in the applications I have developed, so I think I can answer that.


Polling is something which should be avoided, as it requires a lot of bandwidth usage in both client and server side. We don't want our app to use a lot of data on mobile, do we? On the same side keeping the cost of the server minimal is again a good thing.
The delay in receiving messages is again a negative point here. People want immediate delivery of messages (even if they are using a 2G connection) in this decade. It's good to make our apps future ready.


XMPP is one of the best thing you can use for Chat. It has in-built stanzas and structure for most of the things which you can do in a chat application. It's not without any issue though. Horizontal scaling is an issue as you have mentioned. It requires a lot of customization. Another issue is that most of the XMPP servers don't implement all specifications of XMPP which requires further customization. I found it too hard to work on XMPP servers and thus entirely avoid it now.


This is perfect, if you are comfortable in creating your own framework for that. There're libraries such as Socket.io to make it simpler, although all the other thing you have to take care of yourself. I tried it for my app few years ago, but the client library for Android was not that mature at that time.


This is something which I would recommend you to use. This is what most of the beginners are trying these days. You can use FCM for push notification and for faster and reliable way, you can use Firebase Real-time database or Firestore which syncs to multiple clients simultaneously. FCM is free entirely, although the database has some limitations which you can remove by paying. This is one of the cheapest available option too.


This is what I would recommend if you have some advanced usage and require a highly scalable app. This is something new and I have seen many Google developers recommending it to our clients(We are a Google premiere partner and thus have direct access to Google guys whenever any such need arises). I am not entirely sure how can you connect it to Android as I have not worked a lot on this, but this link can help you.

  • How would you horizontally scale websockets? Your continually checking an in memory catch right? All the memory has to be one server unless you're breaking out chatrooms by server? – user2370642 Mar 21 '18 at 12:01
  • Exactly, it's not made for horizontal scaling. gRPC is the solution for this or using firebase. There might be some way to horizontal scale websockets which I don't know. – noob Mar 21 '18 at 12:47
  • @user2370642 "Websockets" is a communication mechanism. It dictates nearly nothing about how the process collects messages server-side. ... E.g., nothing prevents the server-side process managing the socket from broadcasting it's subscriber list and then receiving new messages for those subscribers directly -- via a regular socket. – svidgen Mar 21 '18 at 14:13

Your Answer

