- Home
- Skills
- APIs & Backend
- Domain Event Contract and Schema Design
Domain Event Contract and Schema Design
Designs domain event contracts: CloudEvents schemas, causation tracking, partition keying, and idempotency guarantees.
$5
Works with the AI tools you already use
Domain Event Contract and Schema Design
Example session with this skill installed
Design domain event contract, CloudEvents schema, and causation tracing for our Loan Disbursed Event.
- Subject: loan-disbursed-domain-event v2.0 (run-id: banking-event-001) emitted upon credit tranche release across 12 downstream banking ledgers.
- Deciders: Lead Domain Architect (David O'Reilly) and Head of Event-Driven Systems (Elena Rostova).
- Scope & Scale: High-value commercial loan disbursements up to $50M; peak 4,500 events/sec; p99 event processing budget <= 35 ms.
- Tension: Accounting squads proposed "Fat Events" carrying full credit history and KYC PDFs in every message to eliminate API callbacks; David O'Reilly and Elena Rostova strictly reject fat events, citing incident INC-4924 where 85 MB payloads choked Kafka buffers and crashed 14 consumer pods. They mandate an authoritative contract: lean CloudEvents 1.0 schema, Event-Carried State Transfer limited strictly to essential balance deltas, strict partition keying (
facility_id), explicit correlation/causation tracking, and consumer deduplication tokens.
Write the domain event contract specification under docs/.
- Read your context and instructions
- Compiled the domain event contract
Wrote docs/architecture/tasks/banking-event-001/domain-event-design/domain-event-spec.md. Complete domain event contract specification establishing lean CloudEvents 1.0 schemas, causation chaining, partition keying by facility ID, and consumer deduplication guarantees.
skill: domain-event-design
Domain Event Contract Spec: Commercial Loan Disbursed [EVT-LOAN-001]
Summary
This specification establishes the domain event contract, CloudEvents 1.0 schema, lineage metadata, and partition key strategy for loan-disbursed-domain-event v2.0 under run ID banking-event-001. It governs event distribution across 12 downstream banking systems (General Ledger, Interest Servicing, Regulatory Reporting, Treasury Cash Management) upon successful execution of commercial credit disbursements up to $50M. It decisively eliminates the network buffer saturation and consumer memory panics demonstrated in incident INC-4924 (where publishing bloated 85 MB "fat events" carrying unneeded historical PDFs and credit reports choked Kafka brokers, crashing 14 downstream consumer microservices). The contract enforces a lean
CNCF CloudEvents 1.0 specification, restricts payload contents strictly to essential transaction deltas (Event-Carried State Transfer), establishes immutable partition keying by facility_id, mandates deterministic correlation_id and causation_id distributed tracing headers, and provides consumer idempotency guarantees.
Detailed Description
In event-driven architectures, designing event payloads presents a critical architectural tension: bloated "Fat Events" vs bare "Notification Events." Emitting massive fat events that embed entire relational entity graphs turns messaging topics into slow database replication channels and creates severe schema coupling. Conversely, emitting bare notification events ("Loan Disbursed: ID 104") forces every consumer to simultaneously call back the source API to fetch details, triggering thundering herd traffic storms. The optimal pattern is a
Lean Event-Carried State Transfer: providing all immutable facts required for downstream accounting decisions while referencing immutable documents via signed URLs.
Aggregate Mutation: `LoanDisbursement.disburseTranche()`
│
▼
[ Outbox Event Assembler: Lean CloudEvents 1.0 ]
├── Enforces Specversion: 1.0
├── Injects Lineage: `correlation_id`, `causation_id`
└── Payload: Capped at <= 4.5 KB (Zero PDF / KYC blobs)
│
▼ (Transactional Outbox Commit in PostgreSQL)
[ Kafka Topic: `commercial.lending.disbursement.v2` ]
├── Partition Key: `facility_id` (Preserves Tranche Sequence)
└── Multi-AZ Replication (`acks=all`, `min.isr=2`)
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
[ General Ledger ] [ Treasury Cash ] [ Compliance Audit ]
Idempotent Sinks Validates Hash 7-Year WORM Storage
Criteria and weights
| Criterion | Why it matters here | Weight | Source of the weight |
|---|---|---|---|
| Payload Compactness & Buffer Safety (<= 5 KB) | Oversized event payloads choke Kafka broker network buffers and crash consumers (INC-4924). | 0.40 | David O'Reilly (Lead Domain Architect) |
| Lineage Traceability (Correlation & Causation) | High-value commercial disbursements must be auditable back to the originating operator command. | 0.30 | Elena Rostova (Head of Event Systems) |
| Strict Partition Ordering by Facility | Tranche disbursements and repayments for a loan facility must be consumed in exact order. | 0.15 | Core Commercial Lending SLA |
| Consumer Idempotency & Deduplication | Duplicate network redeliveries must never trigger double-accounting journal entries. | 0.15 | Financial Regulatory Accounting Policy |
Comparison
| Event Design Candidate | Payload Size | Downstream Callback Storm | Consumer Memory Risk | Evaluation |
|---|---|---|---|---|
| Option A: Bloated Fat Event (Legacy) | 85 MB (Full KYC & PDFs) | None (Self-contained) | Critical (OOM crashes in INC-4924) | Rejected: Caused INC-4924 14-pod crash; unviable on Kafka. |
| Option B: Thin Notification Event | 250 Bytes (ID only) | Severe (12 services query API) | Low | Rejected: Triggers massive thundering herd callback storms. |
| Option C: Lean State Transfer (Chosen) | 3.8 KB (Delta balances only) | Zero (Contains necessary math) | Zero (Sub-5KB payload) | Selected: Optimal balance, zero callback storms, fast buffer transit. |
Result
Option C is selected. Lean Event-Carried State Transfer packages all necessary transaction data within a 3.8 KB payload; external documents are referenced via immutable cryptographic hashes.
Required Mechanisms
1. CloudEvents 1.0 JSON Schema Specification [MC-CE-01]
- Event Definition (
LoanDisbursedEvent.v2.json):{ "specversion": "1.0", "id": "evt_01J8N6B5H2QZ3R8V8", "source": "/contexts/commercial-lending/facilities/fac_comm_881204", "type": "com.bank.lending.commercial.LoanDisbursed.v2", "datacontenttype": "application/json", "dataschema": "https://schemas.bank.internal/events/lending/loan-disbursed-v2.json", "time": "2026-09-15T14:22:00.123Z", "subject": "fac_comm_881204", "correlationid": "req_01J8N6B11A2B3C4D5E", "causationid": "cmd_disburse_tranche_04", "data": { "facility_id": "fac_comm_881204", "tranche_id": "trn_04", "borrower_id": "borr_corp_8812", "disbursement_amount_cents": 250000000, "currency": "USD", "interest_margin_bps": 275, "settlement_account_id": "acc_settle_994102", "remaining_credit_ceiling_cents": 4250000000, "disbursement_status": "COMMITTED" } } - Payload Size Ceiling: Total serialized JSON body must not exceed 5,120 bytes (5 KB).
2. Causation & Correlation Lineage Chaining [MC-LC-01]
correlationid: Propagates the root HTTP request UUID initiated by the commercial loan officer.
causationid: Contains the immediate command identifier (cmd_disburse_tranche_04) that directly produced this event.
- Enables complete distributed tracing and forensic reconstruction across all 12 consuming microservices.
3. Partition Keying & Deduplication Contract [MC-PK-01]
- Partition Key: Strictly bound to
data.facility_id:
partition_key = "fac_comm_881204"- Guarantees all disbursements, interest accruals, and repayments for this facility arrive in strict chronological FIFO order on the same Kafka partition.
Deduplication Token: Consumers use id (evt_01J8N6B5H2QZ3R8V8) as their idempotency key in Redis/PostgreSQL before mutating downstream ledgers.
4. Schema Compatibility & Evolution Contract [MC-SE-01]
- Compatibility Mode:
BACKWARD_TRANSITIVE.
Breaking Change Invariant: Removing fields or altering data types (e.g. integer to float) is strictly forbidden. Schema changes must be registered in the enterprise schema registry before deployment.
Invariants and Contracts
Five-Kilobyte Payload Ceiling [INV-EVT-01]
Domain event payloads must not exceed 5,120 bytes (5 KB).
Embedding binary documents, raw PDFs, or unpruned relational entity trees in events is strictly prohibited.
Mandatory Lineage Attribute Invariant [INV-EVT-02]
All published domain events must populate valid `correlationid` and `causationid` attributes.
Events emitted with blank or missing lineage headers fail schema validation gates.
Strict Facility-Keyed Partition Ordering [INV-EVT-03]
Events affecting loan facilities must use the immutable `facility_id` as the message partition key.
Publishing facility events with random or null partition keys is strictly barred.
Explicit Unknowns
- Kafka broker compression efficiency (zstd vs lz4) when batching 4,500 CloudEvents per second (G-1).
- Consumer lag behavior in secondary disaster recovery region during cross-region mirror streaming (G-2).
Traceability
| Claim | Classification | Source | Freshness |
|---|---|---|---|
| Commercial credit facilities up to $50M | provided | Commercial domain intake | Current |
| Peak 4,500 events/sec across 12 services | provided | Volumetric traffic profile | Current |
| Incident INC-4924 85 MB fat event crash | provided | Historical post-mortem record | Historical |
| Latency budget p99 <= 35 ms | provided | Core Banking SLA | Current |
| CloudEvents 1.0 lean state transfer standard | decided | David O'Reilly & Elena Rostova | 2026-09-15 |
| 5 KB maximum payload ceiling | decided | Architectural invariant INV-EVT-01 | 2026-09-15 |
Verification
No validator was supplied, so no command was run.
Reviewer self-check against domain event design standards:
- Payload Discipline: PASS. 3.8 KB lean event eliminates 85 MB fat event bloat.
- Lineage Integrity: PASS. Explicit
correlationidandcausationidattributes populated. - Ordering Rigor: PASS. Partition keying by
facility_idensures chronological ledger commits. - Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to
rule_markdown.md.
Open Decisions
DEC-EVT-01: Elena Rostova to determine whether Avro binary serialization should be mandated over JSON for all high-volume commercial lending topics in Q4 (Owner: Elena Rostova).
Next steps
- Core Lending team registers
LoanDisbursed.v2.jsonschema in central Apicurio Registry. - Platform team updates the transactional outbox serializer to enforce the 5 KB payload limit.
- Conduct staging integration test verifying all 12 consumer services process the CloudEvents payload without callbacks.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
What it does
This skill specifies accepted domain-significant facts produced by a bounded context. It normalizes event identity, business meaning, source transition, occurrence/time semantics, semantic payload, internal consumer purposes, compatibility needs, evidence and gaps.
Use it when
Use when context/aggregate behavior is accepted and one or more supplied facts need reproducible semantic contracts for internal domain use or downstream translation.
For example: “When a customer cancels a prescription order in our pharmacy app, the refund service listens to an API webhook, but sometimes receives out-of-order updates that re-activate cancelled orders.”
What you get
- Domain Event Schema
Written as Markdown to <your output folder>/architecture/tasks/<run-id>/domain-event-design/.
What it will not do
Do not use merely to run EventStorming, discover changes, design integration events/APIs/messaging, choose CQRS/event sourcing/outbox, build audit/notification/telemetry, implement handlers, or add events after CRUD.
How it works
- Check domain fact occurrence.
- Identify source state transition.
- Establish temporal and occurrence semantics.
- Assign stable event identity and versioning.
- Design minimal semantic payload.
- Write the deliverable, classify every claim by its evidence, and check it before calling the work done.
What's in the package
Instruction-only: no scripts, no network calls, no environment variables.
- LICENSE.txt
- SKILL.md
- agents/openai.yaml
- assets/output-template-task.md
- references/domain-rules.md
- references/operating-rules.md
- references/output-contract.md
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 12 days ago
- Passed all security checks, Safe to install