|
|
|
|
|
by hardwaresofton
4080 days ago
|
|
What you've brought up is precisely where relational databases excel -- it's a tradeoff (as anything else, you have to decide when to use one or the other). How many relationships do you have/expect? How intermingled/related is your data? If the answer is "not much" , then maybe you should go with documents, if it's high maybe you should go with RDBMS. Also, the lines are blurred, like I previously stated:
- RethinkDB does joins
- Postgres has good support for storing JSON documents |
|
I think whether or not there are relationships is the wrong way to consider the question of document vs relational. I think of a relational schema as a canonical way to store your data so that you can easily and efficiently project it in multiple different ways (queries).
A document schema stores your data as one possible projection of that data. Obviously you're right that if you can know for sure that one particular projection is the vast majority of queries then this is fine. The problem is that you have to be right about which projection of your data is most important, and normally before you write any code.
In my experience, for greenfield projects it's surprisingly hard to predict what kinds of projections are most important. Often what is interesting to users changes, or you didn't quite have the right projection or whatever.
To compound this, a lot of document stores often don't have good schema migration tools. Migrating schemas and data is actually a lot easier with SQL than anywhere else. Postgres can migrate the schema and the data transactionally and you can rollback if there is a problem in any of the steps. They are also type checked.
Basically, when starting a new project, you are probably better off doing a relational model of your data than anything else. Later, when you know your data access patterns, you can change to a document store and get the various benefits of them without the tradeoffs