PostgreSQL or MongoDB? Start from the access pattern
We use both PostgreSQL and MongoDB in production, and we rarely choose between them on ideology. We choose based on how the data is accessed and how strongly it needs to be consistent.
Default to PostgreSQL when
- Data has clear relationships and needs joins
- You need transactions across several entities
- Reporting and ad-hoc queries matter
- You want one database that can also do JSON, search and queues
Reach for MongoDB when
- Records are self-contained documents read as a whole
- Schemas vary heavily between records
- Write throughput on simple documents dominates
For most business applications, PostgreSQL with JSONB columns covers the flexible-schema cases without giving up relational guarantees. That is why it is our default, and why we document the reason whenever we choose otherwise.