1

I'm working with user accoutns for a telephone system and I need to disconnect users once their balance has reached zero.

  • User initiates call
  • Current balance is retrieved
  • Price for phone call is calculated and it is worked out how many whole minutes the user can purchase
  • Session hangup time is then stored in the database

I need to poll the database (every second?) to find out if the session hangup time is =< now().

Any advice on polling a database this often, I currently use MySQL but I am willing to change.

cron won't run often enough. Because I will be getting billed per the minute I need to ensure that the time of this script is accurate.

I was looking at node.js to do the task, never having used node- is it suitable? Would it be worth using a publish/subscribe function of a database? (can't risk any loss of data as this would mean the user could continue on their phone call forever)

Any advice is appreciated.

P.S everything will be server side. There will be no front end to fire requests.

pavium
  • 13,768
  • 4
  • 29
  • 45

1 Answers1

1

For the note, you might not be approaching this the right way. In so far as I'm aware, what telcos usually do for billing, is to have an in-memory snapshot of the data that is getting changed, along with a periodic batch-update to persist said data as needed.

In DB terms, think of it as working using a proxy table that uses the memory engine, with a periodic begin / rename mem_table / create new mem_table / commit, followed by a begin / update static_table using old_mem_table / drop old_mem_table / commit.

The worst that can happen is to lose a few minutes of billing. The benefit is that it spares the hard drives from doing incessant read/writes (which they can't do anyway, considering the throughput they're facing).

As for your (node.js) issue in particular, why not use setInterval()?

Denis de Bernardy
  • 67,991
  • 12
  • 114
  • 140
  • The issue that I face is that users will have a prepaid amount of credit which approaches zero. Once it reaches that I need to manually disconnect the call, to do this I need to send a REST command. I dont quite follow your answer however should I lose one call ID from memory this call could potentially last forever. I wont have any way of billing users past their prepaid amount. –  May 14 '11 at 13:45
  • Re the answer, I'm merely suggesting (last line) that you do a lookup using javascript directly. Re the infinite call, think of it this way: if the DB server crashes, all calls are probably going to be cut anyway; and at the very worst, a handful of customers will spend an hour or two talking to a friend in Zimbabwe. Your hard drives will be grateful. – Denis de Bernardy May 14 '11 at 13:51