Why I switched from MongoDB to PostgreSQL (Rasmus Porsager)
Audio Brief
Show transcript
This episode covers a developer's journey from favoring MongoDB to advocating for PostgreSQL, highlighting crucial lessons in database selection.
Key takeaways: match tools to purpose, prioritize long-term data integrity, and recognize SQL's enduring value.
Initially favoring MongoDB, the developer realized enforcing schemas with Mongoose nullified its schemaless benefit. This prompted re-evaluating tool suitability.
A MongoDB project later lost structural integrity after handover, causing data chaos. This highlighted the critical need for inherent structural enforcement for long-term maintainability.
This led to embracing PostgreSQL and SQL, previously deemed ancient. It shows established technologies often offer robust, enduring solutions for complex project needs.
These insights offer valuable lessons for any developer navigating modern database choices.
Episode Overview
- The speaker recounts his early programming journey, initially choosing the newer MongoDB over SQL, which he considered an "ancient" technology.
- He discusses his "aha" moment: while using the Mongoose library, he realized he was building schemas on top of a schemaless database, thereby nullifying its core benefit.
- The speaker shares a negative experience where a system he built on MongoDB lost its structural integrity after being handed off to a new team.
- This experience, combined with the growing popularity of Postgres around 2016, led him to switch, and he has been a strong advocate for it ever since.
Key Concepts
- SQL vs. NoSQL: A practical comparison based on a developer's long-term experience, contrasting the initial ease of use of MongoDB with the long-term structural benefits of PostgreSQL.
- Mongoose Library: An Object Data Modeling (ODM) library for MongoDB that allows developers to enforce schemas at the application level on top of the schemaless database.
- Schemaless Databases: The core concept of document-based databases like MongoDB, which offer flexibility by not requiring a predefined data structure.
- Data Integrity and Maintainability: The challenge of maintaining a consistent and predictable data structure in a flexible environment over time, especially as a project is handed off between developers.
- Technology Perception: How developer perceptions of "old" versus "new" technologies can influence architectural decisions, sometimes overlooking the proven benefits of established tools like SQL.
Quotes
- At 00:13 - "I thought it was this ancient thing that wasn't a good idea to use anymore." - The speaker explains his initial perception of SQL when he was a new programmer, favoring the novelty of MongoDB.
- At 00:46 - "So the entire idea behind Mongo being schemaless and document-based, I wasn't using it at all for anything." - He describes his realization that using the Mongoose library to create schemas meant he was effectively fighting against, rather than leveraging, MongoDB's core design philosophy.
- At 02:14 - "Why haven't I given this a shot before?" - His thought after finally exploring PostgreSQL and discovering the directness and power of using SQL for creating structured tables, which he found more suitable for his needs.
Takeaways
- Be mindful of defeating the purpose of your tools; if you find yourself enforcing rigid schemas on a schemaless database, consider whether a relational database like Postgres is a more appropriate choice from the start.
- Prioritize long-term maintainability over initial setup speed. A database with enforced structural integrity can prevent data chaos and be easier for future teams to understand and build upon.
- Re-evaluate established technologies periodically. "Old" technologies like SQL have remained relevant for decades because they solve a fundamental set of problems effectively and reliably.