Ok Ok. I promise this is the last time I will write hailing another database solution as the one that solves all my issues. At least, I hope so.
If you have been following my posts, you may remember that my application stores some data that is very dynamic (i.e. different subtypes that will probably change a lot in the future). I didn’t like creating a lot of relational tables whenever I add a new type. Managing these tables wasn’t a lot of joy either and most database reads in my use cases required tens of joins. All of this made relational databases seem less than ideal. At this point I was introduced to MongoDB and I loved it. MongodB sidesteps this issue completely by embedding all these different types of entities within their parent entity. Suddenly I didn’t have to deal with multiple tables or even modify the database when adding a new type; Reads for my use cases now use a table or two instead of running tens of joins; the world is beautiful! Or is it?
Mongo essentially sacrifices referential integrity between tables. My team leader reluctantly accepted this because he values “developers happiness “, as he puts it, because he realized that the embedding model of Mongo makes our lives considerably easier. It seems he wasn’t that happy about the compromise though, so he dug around and brought me a spork, PostgreSQL.
Postgres is a very popular ORDBMS that efficiently combines the integrity of the relational models with the flexibility and performance of the Object models at the same time. Postgres JsonB data type, which is quite similar to Mongo’s bson representation that stores all their data, has shocked the industry by outperforming Mongo a few years ago. It seems Mongo has improved again surpassing Postgres, but it still remains incredible. A good explanation of this is provided in this article I recommend reading It is also where the title of this post comes from (spork).
So this settles it. The complex objects are stored on JsonB columns while the rest of the database is relational with integrity guarantees. I am quite happy with this arrangement and it seems like the perfect solution but I may have said such words about Mongo before so what do I know. I will keep you posted if any changes happen.