schmudu
schmudu

Reputation: 2243

When is the duplication of database data okay?

When is it okay to have duplication of data in your database?

I'm working on this application that is supposed to track the number of user downloads. From my layman's point of view I can

  1. simply have a column in the user table and increment the counter every time the user downloads something, or
  2. have a counter table that has two columns, one for the user and one for the downloaded file.

As I see it both options enable me to track how many downloads each user has. However if this application sees the light of day and has tons of users then querying the database to look through the whole counter table could be quite expensive.

I guess my question is which do you all recommend?

Upvotes: 1

Views: 224

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173662

There's no data duplication in the second option, just more data.

If you're not interested in knowing which files are downloaded, I go for the first option (takes least space). If you are, go for the second.

At some point, though, you might also be interested to see the download trend over time :) have you considered logging downloads using Google Analytics? They're probably a lot better at this game than you :)

Upvotes: 2

Related Questions