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.