Aggregation Pipeline
Design a small subsystem that relies on Aggregation Pipeline. Outline components, data flow, failure modes, and metrics.
Answers use simple, clear English.
Audio N/AQuick interview answer
Use Aggregation Pipeline as the core idea. Example shape: Monthly revenue by category: $match date range, $unwind items, $group by category sum price..
Detailed answer
Use Aggregation Pipeline as the core idea. Example shape: Monthly revenue by category: $match date range, $unwind items, $group by category sum price.. Watch for: $lookup expensive on large collections without indexes; memory limits on sort/group.. Measure success via latency/error/saturation. Core: Stages: $match → $group → $sort → $lookup (join) → $project. Pipeline runs server-side; push filters early in $match for index use. Real-time example: Monthly revenue by category: $match date range, $unwind items, $group by category sum price. Pros: Powerful analytics in database; reduces app-side processing. Cons: $lookup expensive on large collections without indexes; memory limits on sort/group. Common mistakes: $lookup before $match blowing working set; missing allowDiskUse on huge sorts. Best practices: Index fields in initial $match; $project early to trim fields. Audience level: Mid-level.
Full explanation
Stages: $match → $group → $sort → $lookup (join) → $project. Pipeline runs server-side; push filters early in $match for index use.
Real example & use case
Monthly revenue by category: $match date range, $unwind items, $group by category sum price.
Pros & cons
Pros: Powerful analytics in database; reduces app-side processing. Cons: $lookup expensive on large collections without indexes; memory limits on sort/group.
Common mistakes
$lookup before $match blowing working set; missing allowDiskUse on huge sorts.
Best practices
Index fields in initial $match; $project early to trim fields.
Follow-up questions
Keep going — each follow-up opens more follow-ups