Quick revision
The short answer
I would lead the redesign from access patterns rather than from the old tables: list the main reads and writes with their frequency and latency targets, then shape documents so each important page is served by one or two reads, embedding data that is read together and owned by one aggregate. Some read-heavy data will be duplicated on purpose, with a defined way to keep it in sync. The migration runs page by page through dual writes or a change-stream-fed read model, and before any of that I would honestly ask whether a highly relational domain with ad hoc queries would be better served by PostgreSQL with JSONB.
What to remember
In this answer, we saw that a table-by-table port makes MongoDB join like a relational database without a relational planner, which explains the slow pages. We started from ranked access patterns, designed documents around the top reads by embedding owned data and copying a few fields from shared data, gave every duplicated field a sync rule, and migrated page by page with a change-stream-fed read model and flags. We also kept open the option that a highly relational domain belongs in PostgreSQL with JSONB.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would lead the redesign from access patterns rather than from the old tables: list the main reads and writes with their frequency and latency targets, then shape documents so each important page is served by one or two reads, embedding data that is read together and owned by one aggregate. Some read-heavy data will be duplicated on purpose, with a defined way to keep it in sync. The migration runs page by page through dual writes or a change-stream-fed read model, and before any of that I would honestly ask whether a highly relational domain with ad hoc queries would be better served by PostgreSQL with JSONB.
Background to this question
Porting a normalised schema table by table into MongoDB is one of the most common ways teams end up disappointed with it. Every page now needs five or six $lookup stages, which are joins the database is not optimised for, so latency is worse than the relational system it replaced, and the team concludes MongoDB is slow. A senior engineer is asked this scenario because the fix is not a clever index but a change of approach, and it must be delivered without stopping the product. In this answer, we will see why the port performs badly, how to start from access patterns, how to design documents and controlled duplication, how to migrate incrementally, and when the right answer is to question the choice of database itself.
1Why a Table-by-Table Port Is Slow
A relational database is built around joins. Its planner chooses join orders and algorithms, such as hash joins and merge joins, using statistics, and normalised tables are the expected input. MongoDB's model is the opposite: it is built around reading a whole aggregate, a cluster of data that belongs together, in one document. $lookup exists and is useful, but in a pipeline of six lookups each stage runs once per input document, the planner has far fewer join strategies, and a lookup that is not backed by an index on the foreign field becomes a collection scan per document.
So 25 collections mirroring 25 tables give us the costs of both worlds: the data is split as if for a relational database, and joined by an engine that is not designed to join. The answer is not to tune the six lookups but to stop needing them.
2Start From Access Patterns
The first step I would run with the team is a workshop that produces a list, not a diagram. For each important page or API, what does it read and write, how often, and what latency does it need? We get the numbers from production traffic and logs, not from memory. This turns a vague complaint about slowness into a ranked list, and typically a handful of reads dominate.
| Operation | Per second at peak | p99 target | Data it needs today |
|---|---|---|---|
| Order detail page | 1,200 | 50 ms | order, lines, products, customer, shipments, payments |
| Customer order history | 400 | 100 ms | orders, lines, products |
| Place order | 80 | 200 ms | cart, products, stock, customer, address |
| Update shipment status | 60 | 200 ms | shipment, order |
| Monthly sales report | 1 per hour | minutes | orders, lines, products, regions |
Notice what the table shows. The order detail page runs 1,200 times a second and assembles six collections. The report runs once an hour and could tolerate any shape. The design should serve the top rows with single-document reads and leave the rare, flexible queries to a different tool.
3Design Documents Around the Reads
Now we design documents so that each top read is one document or one indexed query. Data that is read together and owned by one aggregate is embedded: an order owns its lines, its shipping address at the time of order, and its shipment events. Data that is shared and changes independently, such as the product catalogue or the customer profile, stays in its own collection, and the order carries the few fields it needs from them, the extended reference pattern.
Twenty-five collections often become six or eight. That reduction is the point: each collection now represents an aggregate with its own lifecycle, not a table.
4Controlled Duplication and How It Stays in Sync
The customer name and tier copied into orders are duplicates, and that is a deliberate trade: thousands of reads a second become cheaper in exchange for occasional extra writes. But duplication without a rule becomes inconsistency, so for each duplicated field we write down two things: is it a snapshot that never changes, like the shipping address on a past order, or a live value, like the customer's display name; and for live values, how is it updated and how stale may it be. A typical answer is a change stream consumer that updates copies within seconds, with a nightly reconciliation job that finds and fixes any drift.
I also set a limit: if a field is copied into millions of documents and changes often, duplication is the wrong tool, and the page should look it up instead.
5Migrating Incrementally, One Page at a Time
A big-bang rewrite of 25 collections is how such projects fail. Instead, we build the new documents alongside the old ones and switch reads page by page.
- Build the new orders model for the top pageschema and indexes
- Feed it from the old collectionschange stream consumer or dual writes
- Backfill history and reconcilecompare old and new results for a sample
- Switch the page's reads behind a flag10 percent, then 100 percent
- Do results and latency match?YesMove the writes to the new modelNoFix and keep the old reads
- Retire the old collections for that areaonly after writes moved
6 steps in order. Play them, or step through them one at a time.
A change-stream-fed read model is usually safer than dual writes in application code, because there is one writer of truth and the projector can be replayed from a resume token or rebuilt from scratch. Dual writes are simpler to start but risk the two stores diverging when one write fails. Either way, a flag per page lets us compare and roll back, and the team sees latency improve on the busiest page within weeks rather than at the end of a year.
6Questioning the Choice Itself
A leader should also ask the uncomfortable question. If, after mapping the access patterns, most important operations still span many entities with many-to-many relationships, and the business keeps asking for new ad hoc reports, the domain may simply be relational. In that case PostgreSQL, with JSONB columns for the genuinely flexible parts, can give us real joins, strong constraints and flexible documents at once.
I would present both options with evidence: the projected latency and effort of the document redesign, and the effort of moving back to a relational store. Sunk cost in the migration to MongoDB is not a reason to stay. The right outcome is whichever model fits the access patterns, and making that decision openly is part of leading the redesign.
7Follow-up questions
How do you handle the reporting queries after embedding?
Reports with many joins and ad hoc filters are better served by a separate analytics copy, for example a warehouse fed by change streams, or by pre-computed summary collections maintained with $merge. The operational model should be optimised for the operational reads.
When is $lookup still fine?
For rare reads, admin screens, or a single lookup into a small collection with an index on the foreign field. The problem is several lookups on the hottest paths, not lookup as such.
How do you get team buy-in?
By starting with the measured access pattern table and delivering the top page first. A visible drop in p99 latency on the busiest page convinces people more than any design argument, and the same method then applies to the rest.
8Conclusion
In this answer, we saw that a table-by-table port makes MongoDB join like a relational database without a relational planner, which explains the slow pages. We started from ranked access patterns, designed documents around the top reads by embedding owned data and copying a few fields from shared data, gave every duplicated field a sync rule, and migrated page by page with a change-stream-fed read model and flags. We also kept open the option that a highly relational domain belongs in PostgreSQL with JSONB.
Open with
The root problem is that the team modelled MongoDB like a relational database, so every page needs five or six lookups, and MongoDB is not designed to be a join engine.
Then, if they want more
I would lead the redesign from access patterns. First we list the main reads and writes from real traffic, with frequency and latency targets. Usually a few pages dominate, like an order detail page at a thousand requests a second.
Then we design documents so each top read is one document: embed what is read together and owned by one aggregate, like an order's lines, shipping address and shipment events, and keep shared data like products and customers in their own collections with a few copied fields.
That duplication is deliberate, so for each copied field we decide whether it is a snapshot or live, and live ones get a change stream consumer plus a reconciliation job. Migration is incremental: build the new model, feed it from a change stream, backfill and compare, then switch reads per page behind a flag and move writes once it matches.
Finally I would question the choice itself. If the domain is genuinely relational with lots of ad hoc queries, PostgreSQL with JSONB may fit better, and I would put that option on the table with evidence.
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
- MongoDB manual
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 "A team ported a normalised relational schema to MongoDB with 25 collections, and every...": https://scrivio-interview-library.netlify.app/databases/mongodb/6860bc6fc9/