Highlights

Contents

Part VII
07

Case study: a complete data model

We connect the chosen models into one recoverable request path. A specialized read view is useful only when its source, freshness, and rebuild behavior are clear. We will trace a score event, count maintained copies, and defend the smallest design that fits.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Access-pattern-drivendesign2Key-value stores: Redis,DynamoDB3Document stores: MongoDB4Wide-column: Cassandra,Bigtable5Graph databases and SQLvs NoSQL6Eventual consistency andquorums7Case study: a completedata model

#Section 31One authoritative owner per invariant

A scorer submits an event that changes Heron’s score and becomes part of its history. A cache and a search view should not independently decide whether that event happened. An authoritative owner is the component allowed to commit the fact or enforce the invariant that readers rely on.

The score owner validates match identity, scorer permission, expected sequence, and operation identity. It commits the accepted event under a defined transaction or log boundary. Derived read stores then reproduce selected facts. Their faster queries do not grant them independent authority to invent or reorder accepted events.

Ownership can be per match rather than global. Different matches may progress independently, while one match’s sequence remains ordered. Cross-match operations need another invariant boundary if they must succeed together. State that boundary before choosing a partition layout that makes atomicity inconvenient.

Begin with the simplest owner that can enforce the required rules. One relational database may be enough for Heron’s initial score, clip, and history operations. A key-value score cache or graph recommendation view is an addition for a measured query role. Count the new propagation and recovery obligations before assuming the additional store improves the whole system.

ONE OWNER ACCEPTS EVENTS; THE VIEWS ONLY APPLY WHAT IT ACCEPTEDONE OWNER ACCEPTS EVENTS; THE VIEWS ONLY APPLY WHAT IT ACCEPTEDscoreracceptedeventslatest scoresrc pos 1042ordered historysrc pos 1040scorer viewsrc pos 1033positions shown are illustrative; each view records its own
Figure 4.34Illustrative accepted-event owner commits truth before derived read models apply it.

#Section 32Trace an event into its read models

Follow one illustrative event through the design. The scorer request carries match identity, operation identity, and expected sequence. The authoritative owner accepts it once, assigns the next sequence, and commits the source state. This produces a replayable input rather than an untracked attempt to update every store at once.

The latest-score view replaces its match record only with a newer source sequence. The history view stores the event under match, bucket, and sequence. A scorer-oriented view stores the same source identifier under its alternative key. Each view records progress so a restarted consumer can continue or replay safely.

If a consumer fails after applying a replacement but before acknowledging progress, replay repeats the same source version. A correctly conditional replacement remains unchanged. For an incremental effect, retain a deduplication record or use a supported atomic boundary so replay cannot add the effect again. The event identity connects recovery to the original fact.

The viewer reads from the view whose freshness fits the action. After a scorer save, an authoritative or version-aware path can establish read-your-writes. A public history page may permit a declared delay. The system’s claim becomes concrete when it names the source position each view has applied and how a reader handles being ahead of it.

ONE SOURCE ID FOLLOWS THE EVENT FROM ACCEPTANCE INTO EVERY VIEWONE SOURCE ID FOLLOWS THE EVENT FROM ACCEPTANCE INTO EVERY VIEWscorersource ownerid e43, expect seq 43accepted at pos 43latesthistoryscorere43a viewer that needs its own writewaits for pos ≥ 43 or reads the owner
Figure 4.35Illustrative accepted event reaches version-aware latest, history, and scorer views with recoverable progress.

#Section 33Count messages, storage, and recovery work

At 20 illustrative events per second, a source record plus two additional views creates three logical writes per event. That is 60 record writes per second. With three replicas for each representation, count 180 copy writes per second before log writes, indexes, retries, or compaction.

Each source event contains an illustrative 200-byte payload, so the source log carries 4,000 payload bytes per second. Over 86,400 seconds it carries 345,600,000 bytes. Three copies contain 1,036,800,000 payload bytes for the day. These payload totals do not establish the physical capacity of any named product.

Role Source event work Derived obligation
Authoritative event owner Commit once Validate identity and order
Latest score view Replace by version Reject older replay
Match history view Store ordered event Bound bucket growth
Scorer access view Store alternate key Repair missed copies
Replication Maintain copies Detect and repair disagreement

The maintained views add source-load and recovery demands. A one-hour history payload replay has a 14.4-second transfer-only lower bound at the stated 1 MB/s payload rate. Actual catch-up also performs writes while new events arrive. Reserve spare capacity and expose lag before declaring the read model recoverable.

A copy is justified when its repeated read savings exceed the cost and operational difficulty it introduces for this workload. That comparison includes correction and deletion, not only insertion. The ledger makes it possible to remove a view later without losing the fact it once derived.

COUNT THE SOURCE BYTES AND THE COPY WRITES FOR 20 EVENTS/SCOUNT THE SOURCE BYTES AND THE COPY WRITES FOR 20 EVENTS/Ssource payload20 × 200 B4,000 B/sone day4,000 × 86,400345.6 MBthree source replicas345.6 × 31,036.8 MBview copy writes20 × 3 views × 3180/slogs, indexes and backups come on top of this
Figure 4.36Computed illustrative source-log and copy-write totals use the same 20-event/s workload.

#Section 34Adding a new access pattern safely

The product now asks for events by scorer across matches. The original match-history key cannot make that query local. Add an explicitly derived scorer view rather than disguising a full scan as a new endpoint. The source event identity and version make this new route reconstructible.

Begin with a source boundary and capture later updates while scanning retained events. Populate the new scorer keys, apply subsequent changes, and verify that progress reaches a declared readiness point. Use bounded query comparisons to check completeness, ordering, deletions, and duplicate handling. A successful bulk write count alone cannot establish the view’s correctness.

During rollout, keep readers on the old behavior or mark the new results partial until readiness is established. A feature requiring complete history cannot silently serve an incomplete index. If current-only data is acceptable initially, make that reduced scope explicit rather than presenting it as historical coverage.

Retain enough source history for replay, or retain a snapshot and change boundary that rebuild can use. The retention policy of the authoritative source constrains future views. A source that discarded old event identity cannot recreate exact old derived rows merely because the database has room for them now.

A NEW SCORER VIEW GOES LIVE ONLY AFTER BACKFILL, CATCH-UP AND A CHECKA NEW SCORER VIEW GOES LIVE ONLY AFTER BACKFILL, CATCH-UP AND A CHECK1checkpointsource pos2backfillold records3apply changessince checkpoint4verify, thenroute readsuntil step 4, the old path serves readsa partial result must say it is partialthe source must still hold the history the backfill needs
Figure 4.37Illustrative new scorer access path becomes ready after backfill, captured changes, and coverage verification.

#Section 35Defending the model end to end

An interviewer asks why Heron needs several database models. Begin with the operations and invariants, not a product catalog. Show the direct current-score lookup, the bounded match-history range, the clip aggregate, and any measured relationship query. Then identify which owner can accept each fact.

Explain the negative cases. A graph does not improve the known-key score read. A document containing every comment grows without bound. A timestamp-leading row key can concentrate new writes. An eventual derived index is not sufficient for every delete-sensitive or immediately fresh query. These boundaries make the choice precise.

Trace one failure completely. If a history consumer crashes after the source commits, replay follows its recorded position. If an old version arrives after deletion, the tombstone rejects it. If a quorum participant is missing, the membership and acknowledgement protocol decide whether the operation continues. A family label cannot answer any of those histories.

This unit stops at choosing and maintaining data representations. It has not derived consensus, proved an isolation level, or specified a complete distributed transaction. The distributed-systems and database units supply those mechanisms. You can now ask them a sharper question: which ordering and failure guarantee does this particular read or write require?

EACH STORE IS DEFENDED BY ITS QUERY, ITS OWNER AND ITS RECOVERYEACH STORE IS DEFENDED BY ITS QUERY, ITS OWNER AND ITS RECOVERYknown-key scorek → vversioned latest viewmatch historybounded ordered bucketsclip metadatabounded owned documentrelationshipsbounded derived graphone fact owner; every other store is a copy with a rebuild path
Figure 4.38Illustrative review connects each model with its exact query, owner, freshness, and recovery contract.