In recent years, MongoDB and PostgreSQL have gained popularity, representing the NoSQL and SQL camps, respectively. Each technology is optimized for different data modeling approaches: PostgreSQL serves as a general-purpose relational database, while MongoDB functions as a general-purpose document database. While one is more data-centric and the other more application-centric, both can handle similar workloads. PostgreSQL offers flexibility over relational with its JSONB datatype, and MongoDB's flexible schema allows for some normalization through references and schema validation.
However, designing a document database as a relational one is inefficient, and vice versa. Although PostgreSQL can superficially resemble a document database with JSON datatypes, it is not optimized for using it as a document database, because of its block format, query planner behavior, index possibilities, and other components not being optimized for document structures.
In this series of blogs, I'll address some of the problems people may face if they use PostgreSQL as a document database, in order to put some facts for discussions like those I've seen on Reddit:
The idealist argues that JSON in PostgreSQL can replace a document database (reddit):
Because you can just create a table in postgres that is a key and a JSON field and boom, you have a document store. It's really hard to find an advantage that mongo brings at that point, postgres is better in almost every way even at being a document store
The provocateur tweets that Postgres has lots of types, but you really only need 2: SERIAL and JSONB, and followers believe it without realizing it is one of the worst suggestions.
The pragmatist knows that it cannot work at scale (reddit):
I'm not a DBA or anything but this is terrible data design (which you inherited so obviously not your fault). Just chuck the entire data structure as a single json column SMH!
Please, follow for the next posts and here are the slides from my talk at PostgreSQL Germany on this topic:
Be cautious of unverified claims in marketing presentations or social media. Always fact-check information, as execution plans reveal the true scalability of data access. Note that indexing on JSONB has several limitations compared to MongoDB Indexes.
Top comments (0)