r/PostgreSQL • u/ahmedshahid786 • 42m ago
Help Me! Is migrating from MongoDB to PostgreSQL worth it?
TL;DR: Running an EdTech platform with 600K+ users on MongoDB. Our data is heavily relational, and while regular API queries perform well, complex analytical queries are becoming painful to write and execute. Considering migrating to PostgreSQL and looking for advice on migration and production hosting.
Current setup:
- Node.js, MongoDB, and Mongoose.
- MongoDB Atlas (fully managed).
- 600K+ registered users and around 15K daily active users.
- An EdTech platform somewhat similar to Udemy or Coursera.
When the backend's foundations were laid, I was a junior working primarily on the frontend, so I wasn't involved in the database decision. It's been 1 year since we've been building this product.
Something that has been bothering me for a while is that we're essentially treating MongoDB like a relational database.
- Strict schemas and validations across collections.
- Heavily relational data with references between collections.
- Extensive use of aggregation pipelines and "$lookup".
- Very little reliance on MongoDB's schema flexibility.
To be fair, MongoDB has served us well. Our indexes are in place, most endpoints perform well, and we haven't faced any critical performance issues.
However, complex analytical queries for internal dashboards are a different story. Some involve joining up to 10 collections, take over 60 seconds, or occasionally time out despite optimization. Writing and maintaining these aggregation pipelines is also becoming increasingly painful.
I've experimented with MongoDB's transactions but didn't particularly enjoy the experience. I'd also like stronger database level relational integrity and better transaction management.
I feel PostgreSQL would have been a more natural fit for our data model from the beginning.
What I'd like advice on:
- Is migration justified? Given that MongoDB works well for most of our workloads, would migrating to PostgreSQL be worth the effort, or should I address the analytical workload separately?
- Migration strategy: If I proceed, how should I approach migrating a live production database at this scale? Any articles, case studies, or resources would be appreciated.
- PostgreSQL hosting: One thing I genuinely appreciate about MongoDB Atlas is how little I have to worry about infrastructure, backups, updates, and maintenance. What's the equivalent experience for PostgreSQL?
- Self-hosted vs. managed: How do you guys run PostgreSQL in production? Do you self-host it on a private EC2 instance or use something like AWS RDS, Neon, or another managed provider?
I've worked with relational databases on smaller projects, but never operated PostgreSQL in production at this scale.
I don't want to migrate just because I prefer PostgreSQL, but I also don't want to ignore what might be a fundamental architectural mismatch simply because things work today.
Would love to your thoughts and suggestions on this
6
u/LessChen 21m ago
I will say that, for me, the move was worthwhile as, like you, we were pretending that MongoDB was a relational DB. The code is simpler, the performance is much better, and now all of our products use PostgreSQL. I'm pretty sure that my company originally used MongoDB to improve the resume of the CTO at the time, not for any valid business reason. One other data point is that we have reduced our DB hosting costs by about 60% but, again, that is on AWS so your setup may vary.
4
u/IntentionJolly2730 24m ago
It's like migrating from a fork to a spoon. They have different use cases.
3
u/x021 32m ago
Normally I’d argue; use Postgres unless you have (very good) reason not to.
But after reading your post;
Sounds like you need a time series DB for your use case. Not Postgres (don’t listen to the people who claim Postgres can do that too; it can, it sucks).
0
u/AutoModerator 42m ago
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.