Chapter II · Area 06 of 12

Data & state

The Question for Our ShopWho owns the order tables when all modules share a database?

Here you will find approaches for data ownership, storage and reliable state changes.

16 Building blocks

Starting hereData ownership

Three questions for every database

  1. Who owns the data, and where does it live?

    Ownership

    Order owns its tables; product search and images live in suitable stores.

  2. What must stay consistent together?

    Change

    B-1042 and the outbox entry commit together; as separate services, stock and payment would need a saga.

  3. How is data distributed and access accelerated?

    Scaling

    Read replica for customer service, partitions by customer ID, cache in the catalogue.

Known names – and where they are

This is how the building blocks hang together

Data ownership clarifies who is responsible for rules and state. Persistence and polyglot persistence choose the stores, partitioning splits them. Transactions and consistency govern changes, a saga links several; replication and caching keep copies available.

ConceptData ownershipData ownership defines which building block is responsible for data and its domain rules.Decision spacePersistence Models: SQL & NoSQLprovide storage models for the access patterns of the responsible building blockConceptTransaction boundariesdetermine which changes within one data ownership belong together atomicallyConceptConsistency modelsdescribe when readers see changes to owned dataMechanismReplicationdistributes copies and introduces possible delays for the data ownerPatternCachingkeeps derived copies and leaves data ownership with the responsible building blockPatternSagacoordinates local changes across several data ownersMechanismPartitioningsplits the data of the responsible unit across several stores by a keyApproachPolyglot Persistenceassigns each store a task and an authoritative source
Relations: Persistence Models: SQL & NoSQL provide storage models for the access patterns of the responsible building block; Transaction boundaries determine which changes within one data ownership belong together atomically; Consistency models describe when readers see changes to owned data; Replication distributes copies and introduces possible delays for the data owner; Caching keeps derived copies and leaves data ownership with the responsible building block; Saga coordinates local changes across several data owners; Partitioning splits the data of the responsible unit across several stores by a key; Polyglot Persistence assigns each store a task and an authoritative source.

Your learning path through the area

Here you clarify in the shop who owns the order tables, what must hold together when something changes, and how data is distributed and sped up. That tells you who may change state. Each building block shows its theme at our shop.

  1. Data ownership

    Standalone conceptOwnership

    This is what you learnYou can specify exactly one responsible module for order, payment and inventory data.

    In the shopIn the modular monolith, tables are located in a database, but remain assigned to individual modules. Shared storage does not override data sovereignty.

    Data ownership Open
  2. Database per Service

    Standalone concept

    This is what you learnYou must enforce data ownership across separate services while handling cross-service queries, transactions, and migrations. You can compare the three central guarantees.

    In the shopThe current shop remains a modular monolith with seven modules and one shared database; each module owns its tables. A hypothetical service split gives Payment private storage and removes all table access from Order. Order status receives payment information through a versioned contract and projection. The team migrates incrementally, tests permissions, duplicate events, and projection rebuild, and adopts the split only when the quality benefit justifies distributed cost.

    Database per Service Open
  3. Persistence Models: SQL & NoSQL

    Overview & comparisonOwnership

    This is what you learnYou can select a storage model for order letters and product search based on the access pattern.

    In the shopOrders require nuclear status and position changes. Product search requires flexible full text queries across descriptions and categories.

    Persistence Models: SQL & NoSQL Open
  4. Transaction boundaries

    Standalone conceptChange

    This is what you learnYou can determine which order changes belong atomically in a local transaction.

    In the shopThe checkout stores order B-1042 with position P-7 and order amount in the shop database. The charge to the payment provider is an external call.

    Transaction boundaries Open
  5. Consistency models

    Overview & comparisonChange

    This is what you learnYou can formulate different visibility commitments for inventory reservation and customer overview.

    In the shopThe warehouse reservation must check the current stock binding. A customer service overview may show the new shipping status a few seconds later.

    Consistency models Open
  6. Replication

    Standalone conceptScaling

    This is what you learnYou can explain why a copy of the reader can show an older order status immediately after a change.

    In the shopVariant: The shop uses a reader copy of the order database for customer service queries in order to keep many queries away from the writing system.

    Replication Open
  7. Replicated Log

    Standalone concept

    This is what you learnYou can distinguish entry replication, commit index, and application processing and derive a concrete failure test.

    In the shopThe current shop remains a modular monolith with seven modules and one shared database. For a hypothetical standalone order stream, a leader writes each order to a replicated log with three nodes. The platform acknowledges an entry only after the configured majority has stored it durably and marks the committed index. The team isolates a follower, performs a leader change, and proves that the committed prefix remains intact and the returning follower catches up without duplicate business effects.

    Replicated Log Open
  8. Write-Ahead Log

    Standalone concept

    This is what you learnYou can distinguish local WAL durability, crash recovery, and additional replication guarantees.

    In the shopThe current shop runs Catalog, Cart, Order, Payment, Inventory, Shipping, and Invoice as seven modules in a modular monolith with one shared database. For a hypothetical separate payment database, the server confirms an authorization only after the required WAL records are durable. The team terminates the process after commit but before the data page write and verifies recovery after restart. Only an additionally configured synchronous replication rule would include acknowledgement by a second node in the commit guarantee.

    Write-Ahead Log Open
  9. Partitioning

    Standalone conceptScaling

    This is what you learnYou can select a partition key and recognize a cross-partition query.

    In the shopVariant: With a strong increase in order volume, the shop distributes orders according to customer ID on three partitions. The remaining modules remain in the modular monolith.

    Partitioning Open
  10. Caching

    Overview & comparisonScaling

    This is what you learnYou can set an up-to-date rule for each product description, price and stock.

    In the shopThe catalogue shows product texts, prices and available quantities. These values change different times and have different consequences when obsolete.

    Caching Open
  11. Cache-aside

    Standalone concept

    This is what you learnUse cache-aside for repeated reads with an explicit freshness rule.

    In the shopThe Catalog module caches product reads; stock and price changes need suitable refresh rules.

    Cache-aside Open
  12. Polyglot Persistence

    Standalone conceptOwnership

    This is what you learnYou can assign each memory used an independent task and a significant source.

    In the shopVariant: The grown shop keeps orders relational, searches for products in a search index and stores product images in an object memory. The shop remains technically modular.

    Polyglot Persistence Open
  13. Saga

    Standalone conceptChange

    This is what you learnYou can arrange the local steps and appropriate compensations for a failed order process.

    In the shopVariant: Warehouse and payment run as separate services, because independent operation was technically justified. Order coordinates the reservation and the externally connected payment provider.

    Saga Open
  14. Event Sourcing

    Standalone concept

    This is what you learnYou can derive the current order status from an ordered sequence of events.

    In the shopAn experimental order component stores each accepted change to B-1042 as an event. The rest of the shop remains a modular monolith.

    Event Sourcing Open
  15. Shared database

    Standalone concept

    This is what you learnYou can explicitly assign data sovereignty and writing responsibility to a shared database.

    In the shopIn the shop, several modules read order data; the order module remains the sole scribe of the order status. Shipping reports changes through a module contract.

    Shared database Open
  16. Change Data Capture

    Standalone concept

    This is what you learnYou can distinguish CDC from log-based CDC and define a testable contract for capture source, position, schema, and recovery.

    In the shopThe current shop remains a modular monolith with seven modules—Catalog, Cart, Order, Payment, Inventory, Shipping, and Invoice—and one shared database. For a hypothetical search projection, Order writes a business change and an outbox record atomically. A log-based CDC connector reads the committed outbox record, publishes it, and stores its position. The team stops the connector after publication, restarts it, and tests duplicate handling, lag, and schema evolution before adopting this distributed extension.

    Change Data Capture Open
Afterwards in the learning path · area 07Communication & APIs