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





















































