What is a Good Data Model?
To start off with, let us go over what a good data model looks like, what it doesn't look like and what maybe the benefits:
A well data modelled table should
- Be able to retrieve data quickly
- Be able to store data quickly
- Be clear and easy to work with
This essentially what the book refers to as "Simple and Fast".
A well data modelled table should not
- Store unneeded data
- Need to change its rows very often **
- Need too many JOINs to get you the data that you need
Purposes of a Data Model
A good data model should serve a specific and narrow set of purposes.
The more purposes the table serves the:
- More indexes it would need.
- More cumbersome it will be to store and keep in memory.
- More overhead it would be to write to.
- More likely it be a single-point-of-failure
- More likely it would have locks and deadlocks
- More likely it would be to add unneeded data
- More difficult it would be to make changes to your application if you needed to make changes to the table.
If you notice a pattern here, you may notice that reusability to a high degree, may hinder the performance of a database. There needs to be a balance between reusability and single-responsibility of the data models to be effective. I shall write of way to achieve that balance in future chapters.
** A table that has data that needs to change often and is transient, may be better suited in a cache. If it needs to be saved and transactional, then a smaller table that records the state of certain keys or values with a combination of a log to store how it got that way if it is needed.