Quick revision
The short answer
I would move analytics off the nodes that serve the product. Dashboards read from a dedicated analytics member, a hidden or tagged secondary with priority 0 selected through readPreference tags, so heavy pipelines never touch the primary or the secondaries the application uses. Common results are materialised with $merge into summary collections updated incrementally, large or ad hoc analysis goes to a warehouse or lakehouse fed by change streams or a connector, every pipeline gets maxTimeMS and a review for indexes and early filtering, and each dashboard has a stated freshness requirement that decides whether it is served near real time or in batch.
What to remember
In this answer, we moved analytics away from the product's nodes with a dedicated priority 0, tagged or hidden member, materialised common dashboard results with $merge into summary collections, and sent large or ad hoc analytics to a warehouse fed by change streams or a connector. We put maxTimeMS and a pipeline review in front of every dashboard, and used each dashboard's freshness requirement to choose between near-real-time reads, scheduled summaries and batch warehouse jobs.
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 move analytics off the nodes that serve the product. Dashboards read from a dedicated analytics member, a hidden or tagged secondary with priority 0 selected through readPreference tags, so heavy pipelines never touch the primary or the secondaries the application uses. Common results are materialised with $merge into summary collections updated incrementally, large or ad hoc analysis goes to a warehouse or lakehouse fed by change streams or a connector, every pipeline gets maxTimeMS and a review for indexes and early filtering, and each dashboard has a stated freshness requirement that decides whether it is served near real time or in batch.
Why this question is asked
Running dashboards directly against production is how many teams discover that an operational database and an analytics engine are different things. A product manager opens a dashboard with a year-long $group, the primary's CPU jumps to 100 percent, and checkout slows down. Interviewers ask this design question to see whether we can separate workloads, choose the right tool for each kind of question, and set rules that keep it that way. In this answer, we will recap how a replica set serves reads, isolate analytics on its own member, materialise the common results, move large analytics to a warehouse, add guardrails, and use freshness requirements to choose between these options.
1A Quick Recap of Reads in a Replica Set
A replica set is a group of MongoDB servers holding the same data: one primary that accepts writes and several secondaries that copy its changes from the oplog, the replication log. By default, drivers read from the primary. A read preference such as secondary or secondaryPreferred sends reads to secondaries instead, and tag sets narrow that further to members with specific labels.
The problem with dashboards on the primary is obvious: analytics competes with every write. But sending them to any secondary is not much better. Those secondaries also serve application reads, they are candidates to become primary during a failover, and a secondary under heavy load can lag in replication, which affects anything waiting for majority acknowledgement.
2A Dedicated Analytics Member
The first step is a member whose only job is analytics. We add a secondary with priority 0, so it can never become primary, and a tag that says what it is for. Often we also give it votes: 0, so its health does not affect elections or majority write acknowledgement.
Now the dashboard service reads only from analytics-1. The application uses its normal read preference and never lands there, because its tags do not match. A hidden member is an alternative: hidden members are invisible to normal read preferences, so applications never route to them, and analytics tools connect to them directly. Managed services offer the same idea as analytics nodes. The member can have more memory and different indexes in its working set, sized for scans.
Notice the trade-off: analytics now reads data that lags the primary by replication delay, usually under a second but more under load. For dashboards that is almost always fine.
3Materialise Common Results With $merge
Most dashboards ask the same questions repeatedly: sales per day, active users per week, orders by region. Recomputing them from raw documents on every page load is waste. Instead, scheduled pipelines compute the new increment and merge it into summary collections, which dashboards read with simple indexed queries.
There is a catch with incremental updates: replacing a day's total with a total computed from only the changed orders would be wrong. So the job either recomputes the whole affected day for the days touched since the last run, which is what this sketch assumes, or adds deltas carefully. Recomputing affected days is simpler and safe against double counting.
4A Warehouse for Large and Ad Hoc Analytics
Some questions do not fit pre-computed summaries: an analyst exploring churn across three years with many joins, or data science work over the full history. MongoDB is not the right engine for that. We stream changes into a warehouse or lakehouse, using change streams, a Kafka connector, or a managed pipeline, and analysts work there with SQL engines built for large scans and joins.
- Applicationreads and writes on primary and normal secondaries
- Replica set primary and secondariesoperational workload only
- Analytics member, priority 0, taggeddashboards and scheduled $merge jobs
- Summary collectionsdaily_sales, weekly_active and similar
- Change stream or connectorcontinuous export of changes
- Warehouse or lakehousead hoc, multi-year and joined analytics
6 layers, from the top down. Step through them one at a time.
Each layer takes a kind of load away from the one above it.
5Guardrails on Every Pipeline
Even on an isolated member, a careless pipeline can run for an hour. So every dashboard query gets maxTimeMS, a server-side time limit after which the operation is killed, for example 30 seconds. New dashboard pipelines are reviewed like code: does the first $match use an index, are fields projected early, does it avoid $unwind followed by $group where array operators suffice? A pipeline that cannot meet the limit on the analytics member is a sign that it belongs in the summary collections or the warehouse.
We also monitor the analytics member's replication lag and resource use separately, so we notice when the analytics load is growing before it becomes a problem.
6Freshness Decides the Path
The last part of the design is a conversation with the product teams. For each dashboard, how fresh must the data be? The answer chooses the path, and it often turns out that 'real time' means 'within the hour'.
| Dashboard | Freshness needed | Served from |
|---|---|---|
| Live order count during a sale | seconds | analytics member, small indexed query |
| Sales by region today | 15 minutes | summary collection refreshed by $merge |
| Monthly revenue report | 1 day | warehouse batch job |
| Three-year churn analysis | 1 day or more | warehouse, ad hoc SQL |
Writing these requirements down also gives us a contract: if a dashboard is promised 15-minute freshness, its job's lag is monitored and alerted against that number.
7Follow-up questions
Why not just add more secondaries for dashboards?
Untagged secondaries serve application reads and can become primary, so analytics load on them still affects the product and failover. A dedicated priority 0 member with tags keeps the workloads separate.
Does a votes: 0 analytics member risk data loss?
No, it holds a full copy of the data but does not count toward elections or majority acknowledgement, so its lag cannot slow down majority writes. The voting members still provide durability.
What about indexes only analytics needs?
All members of a replica set have the same indexes, so an analytics-only index adds write cost everywhere. That is another reason to serve heavy analytics from summary collections or a warehouse, where we can shape the data freely.
8Conclusion
In this answer, we moved analytics away from the product's nodes with a dedicated priority 0, tagged or hidden member, materialised common dashboard results with $merge into summary collections, and sent large or ad hoc analytics to a warehouse fed by change streams or a connector. We put maxTimeMS and a pipeline review in front of every dashboard, and used each dashboard's freshness requirement to choose between near-real-time reads, scheduled summaries and batch warehouse jobs.
Open with
The core problem is that analytical and operational workloads are competing on the same nodes, so a heavy group over a year of orders can slow checkout. My design separates them in layers.
Then, if they want more
First, a dedicated analytics member: a secondary with priority zero so it never becomes primary, usually votes zero so its lag cannot affect majority writes, and a tag like workload analytics. The dashboard service reads with readPreference secondary and that tag, and the application never routes there. A hidden member or a managed analytics node does the same job.
Second, I materialise the common results. Scheduled pipelines recompute the affected days and merge them into summary collections like daily sales, so dashboards run small indexed queries. Third, large and ad hoc analytics goes to a warehouse or lakehouse fed by change streams or a connector, where joins and multi-year scans are cheap.
Fourth, guardrails: maxTimeMS on every dashboard query, and a review that checks for an indexed first match and early projection. Finally, I ask each team how fresh each dashboard really needs to be, because that decides whether it reads the analytics member, a summary collection or the warehouse, and then we monitor against that promise.
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 "Product teams build dashboards with heavy aggregation pipelines directly on the...": https://scrivio-interview-library.netlify.app/databases/mongodb/9a9cc27fff/