Document stores: MongoDB
We keep related values together when readers and writers use them together. Flexible shape does not remove growth limits, invariants, or migration work. We will choose aggregate boundaries, compare embedding with references, and trace index maintenance.
#Section 11Document aggregates
A viewer opens a clip and needs its title, owner, thumbnail key, and available encodings. A document store keeps named fields and nested values in one record. An aggregate is the bounded group of values the application treats as a useful read or update unit.
Keeping the clip’s encoding metadata together makes the common lookup local. Heron’s illustrative document has an 800-byte base and three 200-byte variant descriptors, totaling bytes. These are metadata descriptors, not the video files themselves. Object storage owns the large media bytes.
The aggregate boundary should follow ownership and lifecycle. A variant descriptor belongs to the clip and normally disappears with it. A shared owner profile has its own updates and can outlive the clip, so copying every profile field creates another propagation problem. A reference preserves that independent ownership.
MongoDB writes are atomic at the single-document level, and it also supports multi-document transactions under its documented conditions. Those facts do not make every related value a good embedding candidate. MongoDB atomicity documentation explains the operation boundaries. Choose a bounded aggregate first, then check the invariants that remain outside it.
#Section 12Embedding versus references
A clip accumulates comments long after upload. Embedding every comment makes a single read convenient at first, but the collection grows independently. Embedding stores a related value inside its owning document. A reference stores an identifier used to find a separate record.
Assume 100,000 illustrative comments of 200 bytes each beside an 800-byte base. The embedded payload becomes bytes. Even before product limits, reading or updating a growing aggregate changes the working set and write contention. An independently paged comment collection avoids loading the whole history for a clip overview.
Embedding is useful when values are bounded, read together, and updated within the same ownership boundary. References are useful when values grow independently, have many owners, or change under a separate lifecycle. MongoDB data-modeling guidance describes these tradeoffs; the decision still depends on Heron's concrete access patterns.
A reference adds another access path, so plan the read. Batch the comment-owner identifiers instead of blindly making one remote lookup per comment. If a page requires a consistent relationship snapshot, state how the database or application provides it. Splitting records removes one growth problem while introducing coordination and lookup work.
#Section 13Schema evolution without surprise readers
A clip title changes from a string field to a translated-title map. Old readers still expect a string. Schema evolution changes stored shape or meaning while readers and writers continue to operate. The database's flexibility does not automatically make incompatible application versions agree.
Begin with a reader that accepts the old and new representations. Then deploy a writer for the new representation, migrate old records in a bounded background process, and verify that no unsupported old records remain before removing compatibility. During the overlap, define which representation wins when both exist.
Store a schema version when it helps distinguish meaning, but do not treat the number as the migration itself. A reader must actually interpret each supported version. Defaults need care: an absent visibility field may mean legacy public content, unknown content, or a malformed record. Choose the meaning before filling the field.
A migration can be retried after failure, so make each transformation idempotent and preserve source identity. Count progress by source records rather than attempted writes. Heron should also reject unsupported future shapes safely, because a rollback may encounter records written by the newer version. Compatibility includes deployment reversal, not just forward migration.
#Section 14Secondary indexes and write amplification
A viewer asks for clips owned by a scorer, but only knows the owner identifier. A secondary index provides another lookup path using fields other than the base key. Its entries point to records or include selected fields needed by the query.
Heron can order clips by owner and creation time, then page through that owner's range. Assume 100,000 illustrative entries of 40 bytes each. One index adds 4,000,000 payload bytes; two add 8,000,000 before structural overhead and replicas. This index-entry size is an input to the exercise, not a product benchmark.
An update that changes indexed values may remove old entries and add new ones. For an illustrative record with two affected indexes, count one base update plus two removals and two additions, or five logical mutations. Actual implementations may batch or represent those mutations differently, but the maintenance obligation remains.
A distributed index can use a different key and freshness boundary from the base store. A fresh base record does not establish that a query through a stale index finds it. State whether the index is authoritative enough for the query, whether missing results are tolerated, and how deletions and repairs propagate to its entries.
#Section 15Building an index while writes continue
Heron adds an owner-and-time view after clips already exist. Backfill populates a new derived structure from existing authoritative records. A scan alone is insufficient when new writes continue, because records can change after their scanned position or appear after the scan's boundary.
Take a consistent source boundary, begin recording changes from it, scan existing records, and apply captured changes in version order. The exact snapshot and change-stream mechanism depends on the source. The invariant is that every relevant source state after the boundary has a route into the new view.
An illustrative 100,000-record scan at 1,000 records per second takes 100 seconds. If 20 new updates per second continue, 2,000 updates arrive during the scan. Replaying at 1,000 per second while new updates continue at 20 gives spare rate 980; clearing that backlog takes seconds, rounded to four decimals.
Do not route readers merely because the scan completed. Verify source coverage, captured-change progress, version ordering, and a known readiness boundary. Compare selected query results with the authoritative source. Keep the old read path until the new one meets its correctness and performance contract, and retain a rebuild plan for a missed update.