I am trying to design an system which can trigger certain events if an action has not taken place. e.g Suppose a person needs to fill 3 forms every hour and if he hasnt then a trigger should take place.

The condition will be different for different users, each hour, each day , each week.

One way is to keep checking the database every minute to check if the action has taken place. But when i have 1000s of users, is this even feasible, also by the time I check every user a lot of time would have passed by which will result in lot of fails.

Any design suggestions?

  • 1
    Could you set a timer, per user, that fires after 1 hour, and which triggers the event on firing? Then, when that user performs some action, the timer is reset (or cancelled)?
    – Castaglia
    Jul 31 '16 at 20:59
  • This is a good idea but wouldnt the timer disappear incase I run the code again or system restarts? Aug 1 '16 at 7:15
  • Are they writing this info directly to the database or are you in control of the client? If you control the client you can easily make something that collects the data and handles thousands of requests per second - the same as any SCADA system. If you have to watch a database you might be better to watch the journals instead of querying the database. Oct 31 '16 at 0:46
  • I am in control of both, what is a SCADA system? Oct 31 '16 at 12:50

I've gone after similar problems a few different ways:

1) Periodically check to see when the action last occurred. If it hasn't happened recently enough, you have an issue. You may need a table specifically to track when a user has filled out a form -- if there aren't three entries for a given user in the last hour, you can fire your trigger. With the right indexes, this should be something you can check frequently, but beware of the boundary times -- when a person first starts for the day, they won't reach three in an hour immediately, for example -- and you'll need a way to find cases where a person has never filled out a form.

2) In an actor-based system, tracking to see if a piece of hardware has fallen off the wireless network, I had the actor reset an inactivity timer each time a message came from that piece of hardware. When that timer fired, I double-checked the time of last activity to eliminate false positives, and if it was over the configured time, that triggered a report the device was off-line.


After a lot of investigation I figured out how to solve it for the language that I am using(NodeJS).

I use an NPM Module called agenda. https://www.npmjs.com/package/agenda With agenda, I set various timers, e.g. At 10:00am , at 9:00pm etc, so if a person has to submit 3 forms between 9-10am, there is a agenda timer set at 10:00am which checks if 3 forms have been submitted. Agenda stores all timers in the database and hence I dont have to worry about system restarts, the data is persisted.

With this I dont have to do an every minute pooling, and this has as of now solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.