liveBook · Manning

Schema

As explained in Grokking Software Architecture

A formal description of the fields and structure of an event message.

A schema describes the structure of data: which fields exist and what kinds of values they hold. Think of it as a contract rather than a bucket. An event schema describes a message’s fields; a database schema defines how stored data is organized. section 7.4.2 section 8.5.2 section 8.2.1

In a relational database, the structure is defined upfront. If a Users table has an integer ID and a string email, adding FavoriteColor means adding a column to the table—not slipping it into just one row. Constraints can enforce the contract too: an explicitly defined foreign key can prevent an order from referring to a nonexistent customer. section 8.2.1

Choose types that guard the data

Store a date in a DATE column instead of a string. The database can reject an impossible date such as February 31st immediately; a string column could accept it and leave reporting code to discover the problem later. Use BOOLEAN for flags and TIMESTAMP or DATETIME for time. Type choices also affect storage and query work. section 8.5.2

Schema design also decides how data is organized and how often it is repeated. An ORM can save objects, but it cannot make that decision for you. Hardcoding different business rules into many separate tables can make a common change painfully repetitive. section 8.4 section 8.6.1

Listing 8.7 The Hardcoded "Trap"
-- TABLE 1: Retail (Hardcoded Structure)
CREATE TABLE Retail_Scorecard (
    id INT PRIMARY KEY,
    revenue DECIMAL,
    same_store_sales DECIMAL -- Retail Logic locked in schema
);
 
-- TABLE 2: Manufacturing (Hardcoded Structure)
CREATE TABLE Mfg_Scorecard (
    id INT PRIMARY KEY,
    revenue DECIMAL, -- DUPLICATE!
    inventory_turnover DECIMAL -- Mfg Logic locked in schema
);

Compare the two scorecard tables: revenue is duplicated, while each table locks a different business rule into its columns. section 8.6.1

A schema must also survive change. When old and new service versions share a database, dropping a column immediately can break the old version. Expand/Contract introduces the new field alongside the old one, then transitions code with dual writes and a historical backfill. During dual writes, deterministic write ordering or optimistic concurrency locks protect migrated data from being overwritten by an older instance. section 13.4.3

Give events a sense of order

OrderPlaced and OrderCancelled events can arrive out of order if they land in different partitions. Include logical sequence numbers or timestamps in the event schema, and make consumers handle out-of-order events gracefully. section 7.4.2

How Grokking Software Architecture covers it

How deep it goes
Explains relational structure and data types, then works through schema maintenance and migration concerns.
Examples
Uses scorecard tables, date columns, an event-ordering scenario, and a customer phone field migration.
What you can do after
Evaluate schema choices for validation and maintenance, and operate schema changes during deployments with overlapping service versions.
How it connects
Connects schemas to normalization, data integrity, event ordering, and backward-compatible migration.

Also explained in

Compare how 54 books explain schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.