I've been developing a real-time JavaScript Application that necessitates immediate synchronization between the database and JavaScript.
Currently, whenever there are changes in JavaScript, an ajax call is made to the API to update the DOM accordingly. The server's API processes the request and sends out a push notification via PubNub to other active JavaScript users with details of the change. To ensure data integrity, each push includes a sequential changeID so that JavaScript can fully resynchronize if needed. Below is an example of such a push:
{
"changeID":"2857693",
"type":"update",
"table":"users",
"where":{
"id":"32"
},
"set":{
"first_name":"Johnny",
"last_name":"Applesead"
}
}
Upon receiving this push, JavaScript updates the local storage and reflects the changes on the DOM based on the affected table. The challenge lies not in updating the DOM but rather efficiently and seamlessly syncing the database with JavaScript.
Reflecting on this process, it seems overly complex for what should be a straightforward task. Is there a simpler way to synchronize multiple JavaScript Clients with a MySQL Database flawlessly? I'm open to suggestions on improving this synchronization process.