Venkat Papana
Venkat Papana

Reputation: 4937

Database Vs Filesystem

I have to maintain the number of user visits for each module of my app. What will be the best option: simple file write or database inserts?

Upvotes: 1

Views: 954

Answers (2)

GordyD
GordyD

Reputation: 5103

I would always go with a database. In a database you are able to create custom reports on user visits using the power of SQL (or another other query language). With a flat file system you would have to create your own bespoke reporting solution to feedback results, effectively building your own database and querying system.

Say for example you used a database (mysql, sql server, oracle, sqlite) and for every visit you recorded a timestamp with the module id e.g.

timestamp,module_id
2010-01-04 10:00:00,1
2010-02-06 10:27:30,2
.
.
.
2011-04-15 18:22:00,5

You would be able to report on the total number of visits for all modules and you could also write a query to find all visits between January 2010 - March 2010 for module 2.

Using a database is also more future friendly, if this a live project, there is always a chance you will want to gain more statistics about your application usage e.g. geographical location of user. Altering your database to store this is very easy, you just alter the table to include a new row and set the default value to something like 'Not known' for all existing records where you did not have this functionality built. You can then write new reporting queries to give you the new information.

So basically in summary, a database is vastly superior. The ONLY downside I see is that it is slightly more resource intensive for a small project that will not grow in reporting scope, but considering today's average computer this really isn't an issue at all!

Upvotes: 1

John Kane
John Kane

Reputation: 4453

Either way really should work depending on your implementation of how you write the file. However I would prefer to use SQLite just because its pretty quick and it does not have that much overhead.

Upvotes: 0

Related Questions