by vanilla-almond · 6y ago · 0 comments
I have not used a GraphQL database, but one of the things I fear about designing a relational database is mentioned in the article:
>"Relational databases are very rigid so you need to really make sure you understand your data upfront. Changing the database is a big effort..." (emphasis is mine)
Given how often requirements change in a business, it seems impossible to anticipate all future requirements at the outset of designing a database. Is it true that changing a (relational) database schema is a big effort? Is this a strong case for GraphQL?
It can be true that changing a relational db schema is a big effort and it can be true that graph (not GraphQL) dbs are more flexible. Even for neo4j and JanusGraph, which don't offer GraphQL by default. They're NoSQL databases that store graphs instead of documents or k/v pairs. It just happens that Dgraph decided to integrate it
- separate internal schemas from external ones, so you can change the internals while maintaining your interface contract. Your database has an API whether you realize it or not, so treat it like one. I literally have schemas like "api" and "api_v2".
- use a great migration tool. I've been using sqitch, which I love because it encourages me to think about how to _verify_ each migration does the correct thing. Tie that into CI/CD in a nice way and DB migrations are no longer scary
That probably downplays the effort; as someone who's never done DBA work before, I've had to learn a lot about PL/pgSQL, transaction isolation levels, role management, etc. for the first time. I think I'm better for it, though, and I've quite enjoyed going beyond query-writing.
1. The data at rest (in your relational database) - database migrations are the solution to this problem, in one way or another. Migrations are well understood, and are not hard - just tricky to get right depending on the complexity of the change. 2. Rules about how to turn that persisted data into something you can reason about at runtime (aka hydration logic) 3. Rules about how to change data from one form or another due to business rules (aka business logic)
If your database is an implementation detail and not the heart of how you reason about your system, then the difficulty in making the migration from one form of data at rest to another should be easier. If you rely on your database for storage and business logic, then you may have a more difficult time.
There're a bunch of changes you can do in Dgraph, that're very convenient. For e.g., going from 1:1 relationship to 1:many relationships (see my comment about movies and directors). Having sparse data models and such.
Then, able to change from int to float, to date -- all these constitute a flexible schema that something like Dgraph is built around, and an relational DB is not -- which all make it easier to iterate upon data models, way better than what relational tables can give.