Question 29 / 50
How would you decide between MongoDB and PostgreSQL for a new backend service?
Short answer
Pick PostgreSQL when relationships, constraints, and ad-hoc joins are the core of the domain. Pick MongoDB when the primary workload is document-shaped aggregates, flexible evolving fields, and reads that want one document rather than a join tree. Many teams run both.
Why?
This is not 'SQL vs NoSQL religion'. Transactions exist in both. Postgres JSONB can store documents; MongoDB can reference. The deciding questions are: what is the unit of read and write, how relational is the data, who enforces the schema, and what the team already operates well. A payments ledger and a reporting warehouse often stay relational; a product catalogue or a CMS often fits documents.
Interview tip
Interviewers are checking that you can say 'it depends' with criteria, not a brand preference.
Common mistake
A blanket 'MongoDB is for scale, Postgres is for consistency'. Both can scale; both can be consistent.
How did you do?
Cheat Sheet