I made a node app that reads every 100ms a table in a MySQL database, which get updated from a other app (lua), and compares the result with the last result. If the table has changed the app will perform an action. The reading process needs ~0.05ms and it works all perfect. But now am I asking myself wehter this is an acceptable solution or very unprofessional.
-
1There's better ways to be notified of a change other then pounding on your database which you are using as an API. – John Conde Mar 29 '18 at 11:56
-
the best option is to program a REST or anny other API interface on the node app that you will trigger with the lua app when the lua app has a update. – Raymond Nijland Mar 29 '18 at 12:25
-
checkout https://stackoverflow.com/questions/37215104/calling-an-url-from-a-trigger-in-mysql – Johan Mar 29 '18 at 12:42
1 Answers
If you are limited with only the database, I would use two timestamp columns like updated_at
and deleted_at
(with indexes maybe - should ask a DB professional) and store the last read time on the client, and then only query the changes made since. This way it'll be more comfortable when using a table with millions of rows.
And except that, It comes to mind that you can use something like websockets to update the client when an update/insert/delete will occur/had occured.
There's another question about this matter:
Which is more efficient to send WebSocket updates with a MySQL database change
Late Edit
Your "If the table has changed the app will perform an action." sentence is probably the key here. You can just check for something like this:
select count(*) from table
where updated_at > last_update_time or deleted_at > last_update_time
then you can decide for to do that action or not.

- 15,371
- 2
- 44
- 78
-
You missed the fact that the update is fired with a lua app.. The node app doesn't fire the update. – Raymond Nijland Mar 29 '18 at 12:21
-
Sure the proplem is that the node app needs to be notified when the lua app has a update that requires some kind off API between them. – Raymond Nijland Mar 29 '18 at 12:25