Software Design Reference Initiative Lead · Design the System

Lesson 0045 · Initiative Lead · Module 2

Design State, Data Ownership, and Contracts

Most integration bugs are unanswered state questions wearing API syntax. Model transitions, ownership, failure, and change before polishing endpoints.

Mission tie-in: data is the durable part of a system. A lead makes its invariants, writer, lifecycle, and compatibility explicit before code makes accidental promises.

Knowledge: state first, transport second

“Return status” sounds like a field. It is actually a state machine with allowed transitions and actors:

Return journey · explicit state model
FromCommandToRule / owner
request returnpending decisionJourney creates one request per intent.
pending decisionrecord eligibilityapproved / refusedEligibility owns decision and reasons.
approvedattach labelready to shipJourney accepts one carrier label.
ready to shiprecord receiptreceivedWarehouse event must match item.
receivedrecord settlementrefundedPayments owns settled-money truth.

The state machine answers what is legal. Data ownership answers who may establish each fact. Prefer one authoritative writer for a piece of state; other modules receive a contract, event, or read model. A shared database does not require shared ownership. If both Journey and Payments can set refunded, the invariant lives nowhere.

For every command, API, or event contract, answer:

Design retries with an idempotency key representing one intent. A client retry after timeout must return the original return and label, not create another. Design consumers as tolerant readers, and evolve persisted data with expand/contract. Compatibility is a delivery feature, not cleanup.

Draw data flows across trust boundaries and minimize data early. The carrier needs recipient name and address for a label; it does not need return reason notes or order history. Record retention and deletion in the model, not only a policy document.

Field notes · contract questions syntax will not answer
QuestionBad defaultDesigned answer
Who may move this state?Anyone with database access.One command owner enforces transitions.
What did timeout mean?Assume failure and repeat.Retry one intent idempotently.
Can a field disappear?Coordinate a big-bang deploy.Expand, migrate readers, contract.
Why retain this PII?Storage is cheap.Purpose, duration, deletion owner.

Skill: locate the durable promise

Who should set “refund settled”?

An idempotency key should identify:

When should privacy enter the design?

Practice: review one critical state transition

Draw the state machine for one initiative entity. For every transition, name command, actor, rule, owner, emitted fact, retry behavior, and audit need. Then choose one cross-boundary contract and document its meaning, failure semantics, compatibility policy, PII, and a contract test.

Reveal: the contract review test

Ask the producer and consumer separately what success, timeout, duplicate, missing field, new field, and deleted user mean. Any different answer is already a production defect; the code has merely not executed it yet.

Your win

You can design a system's durable promises: legal transitions, authoritative writers, safe retries, evolvable contracts, and purposeful data lifecycles.

Read and watch deeper

Ask your agent-teacher to generate adversarial sequences—duplicate, reorder, timeout, stale read, unauthorized identifier—then decide which your contract prevents or absorbs.