FrontierPsycho
FrontierPsycho

Reputation: 743

Multiple App Instances, Multiple DBs or Interconnected Tables?

I am extending an e-voting application with a database. Consider multiple concurrent ballots. For each ballot, several configuration options are stored, and also the votes.

The configuration tables are obviously very small, in the presence of a reasonable amount of concurrent ballots, but the votes table can grow to be extremely large.

My question is this: is it better to have the DB concern only one ballot, and have each ballot create a new instance of the whole DB, or to have a ballot_id foreign key in most tables, and store the data for all ballots in the same DB?

My question mainly concerns performance, especially of insertions in the votes table, once it has grown to be huge.

Upvotes: 0

Views: 103

Answers (2)

Damir Sudarevic
Damir Sudarevic

Reputation: 22187

My rule of thumb -- keep it in the same DB and use partitioning to manage tables. Using partitioning, you can move "old ballot data" to separate drives and have new data "stream into" latest partitions only. For all the practical purposes, current queries access only a fraction of total table size most of the time.

This way you can still use reporting over the whole table (all ballots) without having to joggle between different databases.

Upvotes: 1

Will
Will

Reputation: 1591

If:

  • the ballots once closed effectively become read-only, and
  • are also self-contained and unrelated to other ballots,

Then yes, it would seem to make sense to separate them for performance reasons.

Are any tables shared across all ballots? (eg. app-wide configuration) That information would then need to sit in it's own DB.

Upvotes: 0

Related Questions