DEV Community


Discussion on: PostgreSQL vs MongoDB

gerreth profile image
Gerret Halberstadt • Edited

As mostly, I would say it depends. However, I'd agree with the tenor that for most software applications a relational database (Postgres as my current favourite) might be best suited. If my data is relational in nature, I use a relational database for reasons many commenters already stated. Even though NoSQL might translate to 'Not only SQL', from my experience it is best suited for data models with no or at most very few relations.

Having said this, I do see very valid use cases for NoSQL databases and in some cases would prefer MongoDB. An example I was working with is sensor data. A good data model with MongoDB lets you build optimized solutions for your use case, with trade-offs between read/write operations based on your application requirements. You could look for more specialized (e.g. time-series-) databases, however, these might very well be overkill depending on your needs to store/ingest data. Even for an application with a chat functionality I currently consider using MongoDB based on this article: While at some point Cassandra might be a good solution, I never expect to come close to the amount of data being stored (fingers crossed for the opposite).

For the use cases above, Redis also might be very well suited. Though I still prefer MongoDB here, with Redis as a way to optimize the performance, even more with Lua scripting. Having said this, I am actually building an application using PostgresSQL/MongoDB/Redis together. While this might sound like quite an amount of complexity, all three databases are very easy and transparent to work with (once you get to a certain level). They all have their specialized use cases where at the current stage they work best for me. Secondly, with Heroku/Atlas/Redis you get all those in a free tier, with easy and cheap ways to scale once you need.

Forem Open with the Forem app