Here is my advise
You actually have 3 choices:
- 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)
- 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.
- 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.