Build a realtime chat app which stores messages in a MySQL database

android-developmentiosmobileMySQLreal time

I'm thinking of making a realtime chat app that would allow me to store user messages into a MySQL database. So far these are the two ideas I have.

1) Create and API which the message is sent to and then saved in the database. After the message is saved into the database a push notification is sent to the person who is to receive the message and then a script is run in the background to download the message from the database.

2) Use websockets or XMPP to allow messages to be sent and received by the sever and just save the message to the MySQL database when it reaches the server.

Which one of these methods would be best to implement and scale for a realtime chat application. Method one seems pretty good but I'm not sure if constant SQL transactions are good for a server, the payload might be too much.

EDIT!

So after do some more digging around I see that I can use either XMPP with web sockets or with HTTP to create my real time chat app. My question is what would be a simple but effective way to save these messages to a MySQL database.

Best Answer

Which one of these methods would be best to implement and scale for a realtime chat application. Method one seems pretty good but I'm not sure if constant SQL transactions are good for a server, the payload might be too much.

It seems that one of your main requirements is the technologies of your system to be scalable.

In such case you might like to move to big data platforms such as Apache Kafka, Apache flume, or RabbitMQ.

In that case I would recommend to have a look to Apache Kafka to create an scalable pipeline in which:

  1. A process receives SQL queries from the mobile devices. (Kafka Producer)
  2. A group of servers execute the SQL transaction and reply to the mobile device. (Kafka consumers)

Kafka API will allow you to easily setup this pipeline. While things can get more sophisticated, I hope I gave you an idea of how could you scale your service.

Get started with Apache Kafka: https://kafka.apache.org/documentation/#gettingStarted

Related Topic