Home/ Blog/ Article

PostgreSQL or MongoDB: choosing a database for a new product

ยท

The PostgreSQL versus MongoDB question resurfaces every time a new product gets scoped, and it resurfaces because the honest answer is “it depends” and nobody wants to hear that at kickoff. It is also a decision worth taking seriously: a database choice is one of the few technical decisions in a new product that is genuinely expensive to reverse once real data and real customers are sitting on top of it.

Most of the popular framing for this decision is out of date. The old story was relational for structure and integrity, document-based for flexibility and scale. That story was already fraying a few years ago and does not hold up well now. PostgreSQL has had a JSONB column type, capable of storing and indexing semi-structured documents, for over a decade. MongoDB has supported multi-document ACID transactions since 2018, including across sharded clusters. Neither database is the single-purpose tool it was in 2012, and choosing based on that old reputation tends to produce the wrong answer for the wrong reasons.

The questions that actually drive the decision

Rather than starting from the technology, start from the shape of the problem. These five questions do most of the work.

How related is your data, and how often do you need it joined?

If most of your queries pull together rows from several tables to answer a single question, relational modelling is doing you a favour. A booking system that needs to know a customer’s account status, their outstanding invoices and their upcoming reservations in one screen is a relational problem, and forcing it into a document model usually means duplicating data across collections and then writing application code to keep the copies consistent. If, on the other hand, your core object is naturally self-contained, such as a single event log entry, a device telemetry reading, or a chat message with its metadata, a document model can be a closer match with less mapping code.

Do you need strict consistency, and where?

Financial balances, stock levels, payroll figures, anything with a legal or contractual obligation attached to it, benefit from a database that enforces constraints at the schema level rather than trusting application code to get it right every time. PostgreSQL’s foreign keys, check constraints and transactional guarantees catch mistakes before they become production incidents. MongoDB can enforce similar guarantees within a document and across documents with transactions, but the constraint has to be designed and maintained deliberately rather than coming from the schema for free. For anything touching money or compliance, that difference is worth the extra planning either way.

How settled is your schema, really?

“We don’t know the shape of the data yet” is the most common reason teams reach for MongoDB early on, and it is a weaker argument than it sounds. A JSONB column in PostgreSQL gives you the same schema-on-read flexibility for the fields that are genuinely unstable, while keeping the fields you do understand, such as identifiers, timestamps and status flags, properly typed and indexed. In practice very few products have a data model so unstable that the relational parts don’t matter, and even fewer stay that way once they have paying customers.

What do your read and write patterns look like at scale?

MongoDB’s sharding model is built for horizontal write scaling on high-volume, largely independent records, which is why it shows up so often in IoT telemetry and event-logging systems. PostgreSQL scales reads well through replicas and can be partitioned and sharded too, using tools such as Citus, but it takes more deliberate architecture to get there. For most new products, this question matters less than founders assume, because most new products never reach the volume where it matters. Optimising a schema for a scale you have not validated demand for is a common way to waste the first six months of engineering time.

What does your team already know?

This is the least glamorous factor and the one that most reliably predicts how the first year actually goes. A team fluent in relational modelling and SQL will ship faster and make fewer schema mistakes on PostgreSQL, even for a workload that would theoretically suit MongoDB better. The reverse is equally true. Database migrations mid-build are expensive and rarely scheduled; the tool your engineers already reason well in beats the theoretically superior tool you are all still learning.

The operational question nobody asks at kickoff

Managed hosting has narrowed the gap between the two options considerably. Both PostgreSQL and MongoDB are available as fully managed services from every major cloud provider, plus specialist providers offering features like point-in-time recovery, read replicas and automated failover out of the box. What still differs is the ecosystem around each: the volume of tooling, ORMs, monitoring integrations and hiring pool is larger for PostgreSQL, simply because relational databases have been the default for longer. That matters when you are a small team without a dedicated database administrator, because it shortens the distance between “something is wrong in production” and “we know why.”

Using both is a legitimate answer

Not every product needs to pick one database for its entire lifetime. It is common, and reasonable, to run PostgreSQL as the system of record for accounts, billing and anything with relational integrity requirements, while using MongoDB or a similar document store for a specific subsystem, such as activity feeds, search indexes or high-volume event data, where its access pattern is a genuinely better fit. The cost of running two databases is operational complexity, not licensing, so this only makes sense once the product is stable enough to justify the extra moving part. Introducing a second database on day one of an MVP, before you know which subsystems need it, usually adds cost without adding value.

A checklist before you commit

  • Does your core workflow depend on joining several related entities to answer common questions? Lean relational.
  • Is there money, compliance, or a legal record involved anywhere in the data? Lean relational, or plan transactional discipline carefully if you don’t.
  • Is the genuinely unstable part of your schema a small subset of the data, rather than most of it? A JSONB column may solve the flexibility problem without a second database.
  • Have you validated the scale that would actually require MongoDB’s write-sharding model, or are you assuming it?
  • Which database can your current team build and debug confidently without ramping up first?
  • If the answer is genuinely “both,” is the product mature enough to absorb the operational overhead of running two systems?

If most of your answers point one way, that is your default. If they are split, the deciding vote should go to whichever option your team can operate confidently under pressure, because that is the scenario a database choice is actually tested in.

Filed under: