Published events have a schema

Every event the service publishes has a declared payload, so consumers code against a contract and not against samples.

HighChecked automatically

Applies to:
Services that publish events
Rule id:
events.published-have-schema

Why it matters

An event is a public API with consumers you may not know about. Without a schema they read the payload off the wire and build on whatever they saw that day. The first renamed field breaks them, and nobody finds out until the consumer's data is wrong.

How to apply it

  • Declare the payload of each published event: field names, types and which fields are required.
  • Include a stable event id, the time it happened and the id of the thing it is about.
  • Evolve it compatibly: add optional fields, never rename or remove. A change that can't be compatible is a new event.
  • Keep the schema where the generated AsyncAPI file picks it up.

Example

OrderPlaced { eventId: uuid, occurredAt: timestamp, orderId: uuid, customerId: uuid, totalCents: int, currency: string }

References

Checklists with this rule

Related agent skill: designing-domain-events