I have a node.js server that serves an interactive HTML page to the client browser. SO in this case, the client frontend page is not served from the Apache server but is served from node.js server.
When user perform some actions (i.e. create a wall post or comment), I am thinking of using one of the possible flow of operations to manage them, but I have no idea which one is better (in term of performance, scalability for large amount of users, and ease of implementation). So these are my options:
OPTION 1:
- Socket.io will send the message details to node server (which listens to a particular port). Message will be encoded with JSON.
- Node receives the message.
- Node will communicate directly to the mysql database. Input sanitization is performed at this step.
- Node broadcast the details to the other users who are subscribed within the same socket.io room.
OPTION 2:
- Socket.io will send the details to node server. Message will be encoded with JSON.
- Node receives the message.
- Node calls PHP using HTTP POST. The PHP controller will then handle the HTTP POST message and will save all the corresponding details to the mysql databsase. Input sanitization will be performed at this step.
- PHP will notify node.js server via redis, let's say using a channel called "mysqldb".
- node will subscribe to "mysqldb" channel, and will then broadcast the corresponding details to the users who are subscribed within the same socket.io room.
Can you advise me the advantage and disadvantages of the above 2 approach? Is there any better approach?