Question 30 / 50
Good to KnowMediumScenarioData Modeling
A chat thread is stored as one document with a messages array. What problems appear at scale, and what pattern would you use instead?
Think about it first.
Short answer
The document grows toward 16MB, every new message rewrites the whole thread, and reads pull history the UI does not need. Bucket messages into documents of N messages, or give each message its own document with a threadId index.
Why?
This is the same unbounded-array problem as comments. Bucketing keeps some locality for a page of history without one infinite array. Pagination then becomes 'latest bucket, then previous', not skip on a giant array.
How did you do?
Learn
Cheat Sheet