Embed vs reference is about write amplification, not “relationships” - 007
Embed cheyyala Reference cheyyala? 'One-to-Many' relationship batti decide chestunara? Tappu! Data entha frequent ga update avtundo chusi decide cheyali.
Core Explanation: Embedding baguntundi kani, embedded document ni modify chesthe, entire parent document rewrite avtundi disk meeda (Write Amplification). Reference use chesthe, joins ($lookup) slow avvachu, kani writes cheap ga untayi. So, relationship "Has-A" na "Belongs-To" na ani kadu, "Write-Heavy" na "Read-Heavy" na ani chudandi.
Wrong Practice: Embedding high-churn data (frequently updated).
// User document
{
"_id": "user1",
"name": "Pavan",
"lastLoginLogs": [ ...frequent updates... ] // Bad!
}
Internal: Prati login ki user doc motham rewrite avtundi.
Best Practice: Separate collection for high-write data.
// User Doc (Stable)
{ "_id": "user1", "name": "Pavan" }
// Log Doc (High Churn)
{ "user_id": "user1", "timestamp": "..." }
Closing Insight: "Static data ni Embed cheyyandi. Dynamic/Fast-changing data ni Reference cheyyandi."