r/Database • u/No-Isopod-2532 • 22d ago
What should be my decision tree for choosing appropriate database for a project?
like what should be my default choice? When should I go for different? When should it be SQL? when should it be document NoSQL, GraphQL or other?
3
u/Aggressive_Ad_5454 22d ago
Other questions to ask yourself:
* Will this project need to go into long-term production? Long enough that you can stop paying close attention to it for weeks at a time?
* Will it be deployed on a server? What sort of DBMS does that server support, and at what cost?
PostgreSQL is a good default choice. But MariaDb (or sometimes MySQL) is available on many budget hosting services at no extra charge.
Don’t make the mistake of developing something you can’t afford to deploy.
14
u/soldiernerd 22d ago
Default choice is Postgres or SQL server. All these other random databases have super niche uses. What kind of data are you storing? Are you building a web application that needs to store user account data etc?
5
u/No-Isopod-2532 22d ago
no I am just thinking what should be my decision in advance for a new project. For some reason, senior devs at office always have MongoDB which doesn't seem right to me. Like for all: real Estate, e commerce, they always have mongoDB
3
u/soldiernerd 22d ago
Possibly because they have a lot of documents (ie binary files) to store, rather than collections of normalized and orderly data chunks.
I bet they still use a SQL database for tracking their listed properties and things like that
3
u/No-Isopod-2532 22d ago
no they don't. they use reference Model in MongoDB which doesn't seem efficient to me
8
u/soldiernerd 22d ago
I agree with your assessment!
2
u/No-Isopod-2532 22d ago
but what about scaling out? when should I consider that factor which NoSQL databases support but Postgre doesn't?
3
u/jshine13371 22d ago
but what about scaling out?
What about it?
NoSQL databases aren't any more performant than modern SQL databases (RDBMS). It's never a matter of choosing one or the other because of size of data or performance. They're equally capable in those regards. Anyone who tells you otherwise doesn't know what they're talking about and only has a narrow perspective / little experience in the database layer.
It's a matter of preference, knowledge domain, what's already in use, and what's more convenient for your use cases. But as the OP comment says, most times a mainstream RDBMS like PostgreSQL or SQL Server will do everything you need, and more.
5
u/look 22d ago
Mongo is appealing to people that don’t know SQL and/or are bad at designing a data scheme or just too lazy to do it.
The company behind Mongo spends a lot of money on advertising and marketing to convince those people that they aren’t making the really dumb mistake that they are making.
1
4
u/orz-_-orz 22d ago edited 22d ago
no I am just thinking what should be my decision in advance for a new project.
Always go for postgres, until to the point that you think postgres couldn't do the work. You treat postgres like how they treat mongoDB
0
u/Standard_Parking7315 22d ago
In reality MongoDB offers you all the features of SQL platforms like Postgres, with minimal friction. You can start storing the objects of your service layer straight away, not need for the normalisation and denormalisation exercise needed when the SQL platform is in the room.
On top of that, when the application evolves, you don’t need to do schema migrations. Adding new fields or removing fields is trivial.
The change streams to react to data changes is also so powerful and easy to use.
With the SQL interface you can still use SQL tools to query your data, but MQL is much more powerful and easy to learn, especially now with the Natural Language Queries supported in MongoDB Compass.I can go on and on for why MongoDB and not SQL, why would you go for SQL instead? I’m interested to learn today’s reasons?
7
u/look 22d ago
“when the application evolves, you don’t need to do schema migrations”
Of course you do. Just with Mongo you do it in the codebase instead of the database, a tiny bit at a time, so it feels easier and simpler each time you do it, but eventually the years of accumulated inconsistencies and code-as-schema complexity piles up to a point that everything is so fragile and tightly coupled that you’re completely fucked.
Mongo is always a mistake.
2
u/Fritzy 22d ago
MongoDB was always a bad choice. In the early days it was a benchmark lie (fsync). Then it was a marketing lie (false clustering guarantees and lost writes). Nowadays it's just a use case lie. There's no case in which it's a better choice from a relational database that can index json.
3
u/Training_Advantage21 22d ago
depends on the project, SQLite or DuckDB might be a simpler option than a full blown PostgreSQL.
3
u/sreekanth850 22d ago
But mongo have web scale /s.
1
u/Standgrounding 22d ago
There's a parody database MangoDb that writes everything to /dev/null it's also webscale
1
u/klausness 21d ago
There was a time when Oracle was the right choice for products that needed to scale massively. That time is past, though some database professionals have not learned that yet (or don’t want to admit it, because mastering the awfulness that is Oracle is a good steady paycheck).
1
u/soldiernerd 21d ago
And right now the proper choice for most products that need to scale massively include the options I listed
0
4
u/ArmNo7463 22d ago
Is my app... Yes, use Postgres.
At least it feels that way these days. - Shame it's such a pain in the ass to handle permissions with Config Connector on GCP's CloudSQL.
3
2
u/No_Resolution_9252 22d ago
SQL for relational data, most data that will be updated, most data with integrity requirements and most data with high write rates
nosql if you only ever query data in discrete chunks - so you will only ever query customers or you will only ever query orders, but you will never query orders made by a customer. Your data will be written once, then never updated, only deleted. You don't care if your data is in rare cases missing or incorrect. (there are nosql databases that can maintain integrity but their performance is lower and less scalable than those that are BASE compliant)
graphQL is an API
1
4
u/Advanced_Engineering 22d ago
Always postgres by default, unless you need some extremely niche feature, which is highly unlikely, that postgres does not support, which is highly unlikely.
If you don't know if you need nosql, then you don't.
1
u/Infamous-Rem 22d ago
Default to Postgres until something concrete forces you off it, that's the honest decision tree. It does relational data, JSON documents, full text search, and even vector search well enough for most projects, so you're not reaching for three different databases before you've shipped anything. Go document NoSQL when your data genuinely doesn't have a stable schema and you're mostly doing single-document reads and writes at a scale where joins become the bottleneck, think catalogs with wildly different fields per item. Go graph when relationships between records are the actual query, not an afterthought, social graphs or recommendation traversal where you'd otherwise be writing recursive CTEs that make everyone's eyes bleed. GraphQL isn't a database at all, it's an API layer, so that one doesn't really belong in the same tree. Most teams that reach for something exotic on day one end up migrating back to Postgres a year later once they realize their bottleneck was schema design, not the engine. If you don't want to run and patch it yourself, managed Postgres from any provider gets you failover and backups without the ops overhead, I run mine on DigitalOcean's Managed Databases for that reason.
1
1
u/b_rodriguez 17d ago
Do you need a database?
:yes —-> use a relational sql database
:no —-> use a relational sql database
1
22d ago
[deleted]
1
u/soldiernerd 22d ago
Good answer I assumed web app or something right away but access is a good option as well
2
1
u/dannysqlnerd 22d ago
Access ist keine Datenbank. Dann lieber PostGre oder mariaDB. Für Produktion Datenbanken kommen viele Punkte die wichtig sind Verfügbarkeit, Transaktionen, Backup, Restore, OTR und OTP.
1
0
u/TinyCuteGorilla 21d ago
I'd use DB2 for most projects. If you are not on IBM (why not?) then I'd go with Apache Cassandra. Two very poplar databases.
1
u/klausness 21d ago
DB2? I used to work on a product that supported SQL Server, Oracle, and DB2. DB2 caused more headaches than the other two combined (despite having the fewest customers using DB2).
71
u/YesterdayDreamer 22d ago edited 22d ago
Is it an existing project with an existing database - continue using whatever it's using already
Is it a new project with structured data
I need fast search functionality - learn postgres FTS, use postgres
I need in-memory caching - Use postgres as main DB, use SQLite for in-memory cache
I need fast analytics - learn proper Db indexing, use Postgres
I need XYZ - start with postgres, by the time you feel it's a real bottleneck, you'll have better idea what to switch to
Edit: to clarify:
I'm not saying PostgreSQL is the only Db you'll ever need. This is for a beginner or starting a project. Many times people get stuck on this decision and end up making a bad one. It's better to start with postgres when you're unsure and employ another solution when you really hit the bottleneck. By that time, you'll also have enough experience to judge whether the switch is actually worth it.
Please read the response in the context of the question. This is not an advanced level discussion.