Here’s my app:
When a user tries to access X from my site he is served it and his request is logged (his username).
He can have only 10 requests/servings per day.
Now i can open, read, write to the mysql db without a problem but i was thinking of something that uses less resources, here’s my idea:
Instead of connecting to the DB i create a local file for the user named <date>_<username>.txt, so for example that would be:
2011-06-16_stackoverflow.txt
Then simply do a file exists, if yes, open the file, read the accesses and if <10, allow, and ++1.
(Everyday i do a cron job to delete the last days files based on their date)
Wont this be a less resources solution than using the database for ~40,000 people?
Or is it still recommended to use a DB?
Thanks!
It is an interesting question. But as you know or will know, disk access is the most costly element of an application. In both cases, the server/application will have disk access but in the case of the database server, it will have severe optimizations involved.
In the beginning, using your own system will prove much faster than the database system but building an application requires large vision.
Structured data
What if someday, your application will offer more acess for paying users? Wouldn’t it be very interesting to know which users use your service the most? To have data to define commercial offers? In that case having informations about logging that is queryable will help you a lot.
Scalabilty
What if tomorrow a lot af users start using your application, your I/O wil get saturated. Once again, the database server has several things to prevent that kind of behaviour, cache for example.
Or imagine, your application is deployed on multiple servers, how are you going to do that?
Server migration
Another reason could be server migration. You will have to move the files during progres also. But hey, wait, going from a linux/unix server to a windows server is going to be a really fun task. (Ironic)
…
There are manys reasons out there. Do as you wish. It’s your application. Both are viable, one is standard, the other is homemade. No one can tell you what to do. Just be sure, you’re doing it for the right reasons! 😉