First of all, I must state that this is more of a "strategy" or "algorithm" kind of question, and I'm not sure if it fits the rules here. Please forgive me if this is at the wrong place, and simply let me know where should I ask the question if so. No need to get hostile.
I have also done my research (read questions like Node.js - Monitoring a database for changes or Invoking a PHP script from a mysql trigger) but couldn't find a really satisfied answer so...
My scenario: I'm working a reserve auction site. The product(s) is set at a price says 100usd, and during the auction period (5min-10min) the price will drop (multiple times) to a RANDOM amount at a RANDOM time. These random amount and time are actually already pre-set at the beginning by the seller.
There will be many buyers/watchers, and we need to update them with real time price when the price drop happens. I have been considering different options: 1. I can use node.js to watch certain files (each product will have a file which simply contains the current price of that product, and we will simply use a cron to update these files?) 2. Or, since we already knew before hand when the price changes will happen, we can have, say a "timer" for each product that will wake up at the specific time and notify all users watching it?
I think there could be some better ways as well, which is why I want to post it here and hopefully someone already did something similar can shed some light on me _
Thank you very much in advance.
What kind of database is this ? If it's CouchDB, you can watch for the _changes feed and know exactly when something changed. If those buyers would be in a web browser, it would be easier for them to synchronize with this feed.
If it's another kind of database in which you don't have a changes feed, you should use Pub/Sub and publish to a channel as soon as you update a price. You then listen on another end, and if the buyers are on a web page, you update their views with a WebSocket. Trello's infrastructure is more or less like this (Redis for Pub/Sub, then they hook web sockets in the subscriptions to take the updates to the web page).
I think those are the only ways of doing it in real time. Listening on events. Checking every x ms if something has changed (a.k.a. polling) is not real time.
The easiest way would be to fetch those dates in advance and sending them to the client on page load, then set up the timers on client. If you are strict about security, you can send only the times, and let the client fetch the prices only when it is about to display them. If neither is the option, you could poll the server in regular intervals or, if you can push data to the clients, I would go with the timer on server approach.