You are designing a schema for a social application where each user document stores an array of their last 50 notifications. Notifications are frequently added, and the application only needs to display the most recent 50. Which schema design approach best supports this requirement while minimizing document growth?
The Subset Pattern is ideal when you frequently access a subset of related data. By embedding only the 50 most recent notifications and moving older ones to a separate collection, the user document remains small and queries for recent notifications are fast, directly meeting the requirement.
Why this answer
The Subset Pattern is the best fit because it keeps only the most frequently accessed data (the latest 50 notifications) embedded in the user document while offloading older notifications to another collection. This keeps the document small, avoids hitting the 16MB limit, and ensures fast access to recent notifications without unnecessary complexity.
Exam trap
The trap here is assuming that any pattern that reduces document size works, but the Subset Pattern specifically addresses the need to keep a capped, frequently accessed subset embedded while moving the rest elsewhere.