5

I have to provide free demo of some service to end users in my application. Free demo could be of 30 mins, 1 hours, 5 hours etc. (predefined time) for a new user for one time only.

User can also consume that time in parts. like in 30 mins of free demo, they can use like 10 mins today, 15 mins tomorrow and rest of the time on next day etc. Now If a user opt the free demo of 30 mins and logged in & using the service. I can restrict the user for 30 mins via his start time & end time. I can send them to payment page if sum of start & end-time is equals to 30 min.

Now problem arises with some uncertain conditions like what if user closes the browser or their internet stopped working or anything else at their end during their active session. In this, I can't calculate their consumed time because of lack of endtime.

Scenario could be like below (for 30 min demo).

UserID  StartTime           EndTime             Consumed(mins)
10      09-04-2015 10:00    09-04-2015 10:10        10
10      10-04-2015 05:00    10-04-2015 05:04        4
10      11-04-2015 07:46    11-04-2015 07:56        10
10      11-04-2015 10:00    // Browser closed or any uncertain condition
10      11-04-2015 11:00    // How to restrict user to use actual 30 mins because I do not have EndTime in above row to calculate Consumed mins.

I may have more than 100000 users at the time same to use our services, So I am finding an efficient solution for this.

As per my understanding, I can create a Separate Job to check user's LastActiviteTime and based on that I can update their Consumed(mins) in database. That Job would be executed every minute and also on the other hand, browser of each session user would update the LastActiveTime in database.

This can solve my problem but I'm not very sure about the performance of my application because of huge number of database request per minute.

John Saunders
  • 157,405
  • 24
  • 229
  • 388
Jitendra Pancholi
  • 6,617
  • 8
  • 39
  • 72

3 Answers3

1

You could probably also do the Start, End time validation trough client script with JavaScript and store the Start time, end time in browser cookie and run an timely script (java script that executes every minute), so if the validation fails on the client side itself you don't need to validate it on the server(database) side, this way a lot of user queries to the db will be cut down.

Rolwin Crasta
  • 3,951
  • 3
  • 29
  • 44
  • but what, if user closes it's browser in between – Jitendra Pancholi Apr 09 '15 at 06:16
  • your javascript that runs every minute should also keep updating the LastActive time every minute in the cookie as well. So whenever the users closes the browser and reopens it, you can use this LastActive time - starttime for comaprision – Rolwin Crasta Apr 09 '15 at 06:30
  • if user opens the application in different browser next time or clears the cookies to fool the application. – Jitendra Pancholi Apr 09 '15 at 06:48
  • In that case you still have the server side db validation right.. the Client side validation is not an alternative for the server side database validation, its only a way to bring down the number of server side validation requests. You still have to keep the server side database validation. – Rolwin Crasta Apr 09 '15 at 07:54
  • Suppose in each 10 min, I'm making db request using the script (js) to update the database. Now in one scenario, 10 sec before the db hit, user closes the browser or clears the cookies, in that case user has basically fooled server by 9 mins 50 seconds of use. – Jitendra Pancholi Apr 09 '15 at 09:46
0

I'd suggest conducting a performance test to assess the impact on the database with a bit more than the maximum load expected. Then, depending on the outcome, you might consider using a NoSQL solution like RavenDB to persist usage data. NoSQL could work wonders and is a great match for such problems.

Of course, you can do this with scheduled client-side script and AJAX as Rolwin C already suggested. Just keep in mind that even though there are some obstacles in the way of malicious users, there is always a level of risk taken with this approach. So see if this risk is acceptable in your case as it can greatly decrease the burden on the database server.

Plamen Petrov
  • 4,669
  • 4
  • 28
  • 40
  • 1
    Application is already built up and running and I only have to add this feature to it. Relational database (Sql Server 2012) is using and I can not change it to NoSQL. – Jitendra Pancholi Apr 09 '15 at 09:51
  • I suggested using NoSQL in addition to the existing relational database. In an ideal world this will be a good option. But of course, it depends specifically on your case if the effort is worth it. Anyway, I still think you should do a performance test - you may be fine with the database as it is. – Plamen Petrov Apr 09 '15 at 10:04
0

If user is interacting with your service, use these interaction instances as last used time, and if there is need to identify time when you don't have end time, use last interaction time as time to identify end of a session.

simplest would be adding one more column to the table you have showed as lastInteractionTime. And if there is no end time use that lastInteractionTime to calculate consumed time.

Guanxi
  • 3,046
  • 19
  • 33
  • 1
    That would increase the database hit per activity & may crash the server? – Jitendra Pancholi Apr 10 '15 at 07:42
  • 1
    Don't think so. Depends on how to optimize it. Aren't you already doing any kind of logging for your service requests? And yes, as Plamen mentioned, you need to decide on which option is worth it. – Guanxi Apr 10 '15 at 11:35