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.

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?

    Changes

    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.

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 spaceSQL & 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: 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. 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. SQL & NoSQL

    Ownership

    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.

    SQL & NoSQL Open
  3. 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
  4. 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
  5. 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
  6. 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
  7. Caching

    Scaling

    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
  8. 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
  9. Saga

    Changes

    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
Afterwards in the learning path · area 07Communication & APIs