Contracts and Messaging
Owned APIs and events connect independently maintained BookWorm capabilities without sharing business state.
Cross-cutting Concept
Purpose and Scope
Contracts and messaging preserve service autonomy by preventing cross-service data access and making every interaction explicit. They govern synchronous APIs, AI and tool protocols, integration events, and the durability assumptions of asynchronous delivery across all capabilities.
Visual Reference
Contract and Delivery Pipeline
Loading graph...
Core Rules and Standards
- Keep data ownership local. No capability reads or writes another capability’s authoritative store.
- Use the owned contract. REST, gRPC, AI tool, agent, or event schemas belong to the owner and must describe stable externally visible behavior.
- Version compatibility explicitly. Prefer additive evolution and backward-compatible defaults; treat renaming or removing fields and changing semantics as breaking changes.
- Carry meaningful envelope metadata. Include message identity, event type and version, source, correlation, trace context, and causation where applicable.
- Treat delivery as at least once. Consumers must tolerate duplicates, retries, restart recovery, and out-of-order work unless a documented protocol provides stronger guarantees.
- Make side effects idempotent. Use stable operation or event identifiers to detect duplicate execution and verify authoritative state before compensating.
- Route exhausted work safely. Retry only bounded, classified failures and isolate poison or permanently invalid records for review.
Warning
Schema compatibility is necessary but not sufficient. A field-compatible change can still break a consumer if names, units, meaning, ordering, or ownership semantics change.
Mechanism / How It Works
| Contract Type | Standard | Evolution Rule |
|---|---|---|
| HTTP | Versioned resources and explicit media behavior | Add optional fields and endpoints; retire old behavior through a published transition |
| gRPC | Stable typed schemas and validated operations | Use schema compatibility checks and avoid renaming or repurposing fields |
| Agent and tool protocols | Authenticated, least-privilege operations with machine-readable schemas | Change permissions or tool behavior only through reviewed policy and consumer updates |
| Integration events | Immutable intent, stable event identity, and self-contained enough data for consumers | Add fields without changing existing meaning; publish new event types for semantic changes |
Messaging Pipeline
| Stage | Responsibility |
|---|---|
| Publish | Validate and serialize from the owner; assign message identity and correlation |
| Transport | Preserve envelope metadata and delivery acknowledgement |
| Persist | Select outbox, inbox, or idempotency storage according to durability and duplicate needs |
| Consume | Validate compatibility, enforce authorization, execute idempotently, and commit state atomically where possible |
| Fail | Classify transient, permanent, and poison failures; retry transient work; route exhausted work for inspection |
Verification and Governance
- Run consumer and provider contract checks before merging contract changes.
- Verify additive and breaking schema changes against published baselines.
- Test duplicate delivery, replay, missing metadata, partial commit, and exhausted retries.
- Confirm production partitioning, retention, access, and replay ownership with the broker operator.
- Document event semantics and business effects, not only payload shape.
Related Documentation
- API and contracts indexCustom DocAPI and contracts indexConsolidated index of BookWorm HTTP v1, gRPC, AG-UI, MCP, A2A, and Kafka/Wolverine contracts grouped by service with aut...Ownerplatform-engineering-teamOpen doc — Contract inventory.
- Testing and Change SafetyCustom DocTesting and Change SafetyLayered tests and schema checks protect BookWorm behavior, service boundaries, and contract compatibility.Ownerarchitecture-enabling-teamOpen doc — Contract and compatibility gates.
- Validation, Errors, and ResilienceCustom DocValidation, Errors, and ResilienceShared request validation, HTTP error mapping, and capability-specific retry and duplicate-request behavior.Ownerplatform-engineering-teamOpen doc — Failure and retry standards.