Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Several teams use PostgreSQL jsonb columns as a document store instead of adopting MongoDB. How do you set a policy on when jsonb is acceptable across the company?

We would allow jsonb as a document store when the documents are owned by one service and queried through a few known, indexed paths, and require schema governance for them: a JSON Schema or typed classes in code, a version on every document shape, and a migration plan for shape changes. Data shared by many teams or used heavily for reporting belongs in typed columns. Running one database engine instead of adding MongoDB is a strong argument in jsonb's favour, so the policy also sets limits on document size, TOAST cost and index bloat.

Why this question is asked

When several teams independently start using jsonb columns as a document store, a company has two risks: banning a useful tool that saves it from running a second database, or letting every team invent its own unstructured data that nobody else can use. A policy has to say yes to the good cases and no to the harmful ones, in terms engineers can apply without asking a committee. Interviewers ask this to see how we turn technical trade-offs into a standard. In this answer, we will weigh jsonb against adopting MongoDB, define when jsonb is acceptable, set governance rules, name what stays relational, and add limits on size and indexes.

1A Quick Recap: What Teams Are Really Choosing

A document store keeps each record as a self-contained document, often JSON, rather than as rows across normalised tables. MongoDB is built for this. PostgreSQL's jsonb type gives much of the same: documents in a column, GIN indexes for containment queries, jsonpath for navigating them, plus transactions, joins and the rest of SQL around them.

The comparison is not only about features. MongoDB would be a second database engine for the company, with its own backups, upgrades, monitoring, security reviews, drivers and on-call knowledge. The policy question is therefore not 'is jsonb as good as MongoDB?' but 'under which conditions does jsonb inside our existing PostgreSQL serve a team well without hurting others?'

2The Strongest Argument for jsonb: One Engine

Every additional database engine costs a platform team real effort: backup and restore procedures, patching, capacity planning, security hardening, observability, and engineers who can debug it at night. For a company already running PostgreSQL well, adding MongoDB for a few document-shaped use cases could cost more in operations than it saves in development. jsonb lets those use cases live in a system the company already knows how to run, and it keeps documents next to relational data in the same transaction. So the policy starts from yes, with conditions.

3When jsonb Is Acceptable

The conditions follow from where jsonb works well. The documents are owned by one service, which is the only writer and controls their shape. They are read mostly as a whole or through a small number of known paths, and those paths are indexed with GIN or expression indexes. Their shape varies between records or changes often enough that columns would mean constant migrations. Typical examples are user preferences, form submissions, a product's category-specific attributes, or payloads received from partners.

Step throughIs jsonb acceptable for this data?
  1. Is it owned and written by one service?
    YesContinueNoUse typed columns
  2. Is it queried through a few known paths?
    YesContinueNoUse typed columns or a search engine
  3. Do other teams or analysts rely on it heavily?
    YesUse typed columns, maybe with jsonb for extrasNoContinue
  4. Documents typically under a few KB, rarely partly updated?
    Yesjsonb is acceptable, with governanceNoRedesign: split or move hot fields out

4 steps in order. Play them, or step through them one at a time.

Notice the third question in the flow. If many teams depend on the data or it feeds reports, it needs typed columns, whether or not jsonb would be convenient for the owning team.

4Schema Governance for Documents

jsonb means the database does not enforce a schema, so the policy requires one somewhere else. Each document type has a schema, either a JSON Schema file in the service repository or typed classes in code, such as Java records serialised with Jackson, and writes are validated against it at the service boundary. Each document carries a version field, for example "schemaVersion": 3, so readers know which shape they are looking at.

Shape changes need a migration plan, just as column changes do. Usually that means readers that accept both the old and new version, writers that write only the new one, and a background job that upgrades old documents in batches, after which support for the old version is removed. The plan is part of the pull request that introduces the change.

Java
// Java side: the document shape is a typed record, validated before it is stored
record PreferencesV3(int schemaVersion, String language, boolean emailOptIn, List<String> topics) {}
// SQL side: a cheap guard that the version field is always present
ALTER TABLE user_prefs ADD CONSTRAINT prefs_has_version
CHECK (doc ? 'schemaVersion');

5What Stays Relational

Data shared by many teams or reported on heavily stays in typed columns. Analysts and BI tools work best with columns that have types, names and documented meanings; a jsonb document whose shape depends on a version field and a category is hard to query correctly and easy to misreport. The same goes for data with integrity rules between records, such as foreign keys, unique constraints across fields, or money amounts. A hybrid is fine: core fields in columns, the long tail in jsonb.

Policy summary
SituationDecision
One owner, few known indexed pathsjsonb allowed, with schema and versioning
Shared by several teamstyped columns, published contract
Heavy reporting or analyticstyped columns or export to the warehouse
Needs foreign keys or cross-field constraintstyped columns
Large documents updated in part oftensplit out hot fields, size review
Free text search across documentsconsider a search engine

6Limits on Size, TOAST and Indexes

The policy also covers performance traps. Documents above about 2 KB are compressed and stored out of line in TOAST, and any update rewrites the whole document, so large documents that change often generate heavy write and vacuum load. GIN indexes on large, frequently updated documents grow and bloat quickly, and their pending list can make some writes slow. So new jsonb tables declare their expected document size and update rate in review; documents expected above, say, 100 KB or updated many times per minute need a design discussion; and the platform team monitors index bloat on jsonb tables like on any other.

7Follow-up questions

When would you approve MongoDB instead?

When a team's needs go beyond what PostgreSQL does well, for example horizontal write scaling across shards built in, or very large document volumes with access patterns that MongoDB's features fit far better, and the team accepts the operating cost or a managed service covers it. The bar is a concrete requirement and a plan for backups and on-call, not developer preference.

How do you enforce this policy without slowing teams down?

Put the checklist in the schema review that already happens for migrations, provide a template for a versioned jsonb document with validation and an index, and let teams self-approve when every condition is met. Only exceptions need a platform review.

Can PostgreSQL validate JSON Schema itself?

Not natively. Extensions exist for JSON Schema validation, but most teams validate in the service and add a few CHECK constraints for critical invariants, such as required fields and types.

8Conclusion

In this answer, we set a policy for jsonb as a document store. One database engine instead of adding MongoDB is a strong argument for jsonb, so the policy starts from yes. jsonb is acceptable when one service owns the documents and queries them through a few known, indexed paths, and it requires schema governance: a JSON Schema or typed classes, a version on each document and a migration plan for shape changes. Data shared by many teams or used heavily for reporting stays in typed columns, and size limits, TOAST cost and index bloat are reviewed for large documents.

What to say in the interviewAbout 90 seconds aloud

Open with

I would write the policy as a yes with conditions, because keeping one database engine is a strong argument: adding MongoDB means another system to back up, patch, secure, monitor and be on call for. jsonb is acceptable when the documents are owned and written by one service and queried through a few known paths that we index, with GIN or expression indexes, and when their shape varies enough that columns would mean constant migrations, like preferences, form submissions or partner payloads.

Then, if they want more

In exchange, I would require schema governance: a JSON Schema or typed classes in code, validation at the service boundary, a version field on every document, and a migration plan for shape changes, where readers handle both versions and a background job upgrades old documents.

What stays relational is data shared by many teams or reported on heavily, because analysts need typed, documented columns, and anything that needs foreign keys or cross-field constraints. A hybrid of columns plus jsonb for the long tail is fine.

Finally, the policy covers performance: documents above a few kilobytes are TOASTed and rewritten on every update, and GIN indexes on busy documents bloat, so large or frequently updated documents need a design review. I would put the checklist into the normal schema review so teams can self-approve when they meet it.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
PostgreSQL documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Several teams use PostgreSQL jsonb columns as a document store instead of adopting...": https://scrivio-interview-library.netlify.app/databases/postgresql/c6262d9f7a/