4

Hello I'm going to implement a social chat app that I what it to meet some requeriments but I'm not sure how to achieve this.

Required:

  • The app "frontend" should be written in React Native

  • Support end to end encryption

  • Support user to user chats

  • OAuth2.0

  • Push notifications

  • History

  • Django or Node backend

The problems comes in the backend design. I'm thinking on Node.js with websockets or Django with channels but I don't know which is a good DB design to store chats (like telegram) nor how to build a message queue.

Can anyone give me some tips on the design of a chat app? Thanks

ant1
  • 191
  • 15

2 Answers2

6

Here is my advise

You actually have 3 choices:

  1. Build everything from scratch (as you wrote in your initial question).

It's actually does not matter here will you use Node.js Websockets, Django Channels or Rails Action Cable. They will have pretty the same performance (or maybe Node.js will be a little bit better). You also can use any DB for this: MySQL, PostgreSQL or MongoDB.

For example, you can have these DB tables structure:

Conversations

  • id
  • created_at
  • updated_at
  • type
  • name
  • description
  • avatar
  • participants_ids
  • last_message_id
  • owner_id
  • unread_messages_count

Messages

  • id
  • created_at
  • updated_at
  • conversation_id
  • text
  • sender_id
  • recipient_id
  • attachments_ids
  • read_ids
  • delivered_ids

Users

  • id
  • created_at
  • updated_at
  • login
  • fullname
  • avatar

Attachments

  • id
  • created_at
  • updated_at
  • type
  • link

Then, all your users will have a persistent websocket connection with your server and will use it to send/receive messages. Your server will store all messages in DB in appropriate tables.

Also, you Server will provide REST API to retrieve a list of conversations, messages, attachments, other users profile.

I would say, this option is for small load, small amount of users (because of chosen technologies (Node.js/Python/Ruby) and also because you will build it by yourself, not sure you have enough experience in real time apps building)

  1. Use some open source Chat server, like Ejabberd, Tigase, Openfire. They actually already implemented all real time chat things and have good high-load capabilities (people spent 10 years for building them). You just need to integrate them with your App Server.

Probably your App server will provide REST API to retrieve a list of conversations, messages, attachments, other users profile.

Chat server will provide a way to connect, send/receive messages. You also need to write a plugin for chosen Chat server which will track all messages and put them in you Server App DB.

  1. Use some ready to go Cloud Messaging platforms. There are also many examples in the wild, e.g Twillio, ConnectyCube, Layer etc.

For example - ConnectyCube - Messaging and Video calling provider with messaging capabilities, user base, push notifications, video calling, chat bots. You can integrate your App Server with its REST API. Or even do not write your own App Server at all and use completely this platform. Hence save lots of time and money.

With such platforms you do no care about server hosting, server monitor, server up-time and others server related stuff, you just use their APIs and SDKs in your app. Mostly such platforms provide FREE plans along with dedicated Enterprise solutions where you own your data (it is deployed on your own AWS account for example). So highly recommended.

So something like these is possible in your case.

Rubycon
  • 18,156
  • 10
  • 49
  • 70
  • After reading your advice I think I'm going with Ejabberd since is easier than develop the chat by myself and is free. So probably I will manage the user authentication, profile and metadata,... throw my Django or Node server and let the chat features to the Ejabberd one. Now my question is if is possible to create a "channel" between my server and Ejabberd to share the authentication and user data. – ant1 Sep 07 '18 at 12:38
  • @Antonio you can ask a separate question and I will provide an answer there – Rubycon Sep 07 '18 at 13:33
  • I published the question here https://stackoverflow.com/q/52224543/4202521 – ant1 Sep 07 '18 at 14:24
0

Here is a tutorial of AWS. It uses Node and Redis as the backend.

I followed the tutorial and built a online chat app, which fulfills all your requirements except for the first one because my app only needs web clients.

BTW, I used Redis to do clustering and DynamoDB to save all messages because I am not quite sure about the reliability of Amazon ElastiCache for Redis. In my test Redis works well and it didn't lost any message in 3 months, but my workmates insist that Redis is not reliable(well, they did not provide any data to prove that), as a result I added DynamoDB to ensure the reliability.

Renwei Liu
  • 146
  • 3