# [Luc van Donkersgoed The Tao of Event-Driven Architectures](https://www.youtube.com/watch?v=9r9WDzzTcr0) ## Rules 1. Use JSON for all events. 1. Specifically, do not use anything else (such as XML, text, YAML, etc.) 2. JSON integrates well into the computer landscapes 2. Use an event envelope. 1. Standardized formatting facilitates message filtering ```json { "metadata": { "event_time_iso8601": "...", "event_type": "...", "event_version": "...", "event_id": "<uuid>", }, "data": { } } ``` 3. Use a unique event ID. 1. Have the producers create a unique event id and add it to the `metadata`. 4. Use schemas and contracts. 1. Schemas define the event formats. 2. Given a contract, the consumers can build before the producers exist. And producers can evolve as long as they adhere to this contract. 5. Maintain backward compatibility. 1. Non-breaking changes - usually additions to events. 2. Breaking changes - changes that affect downstream systems. 1. New `event_version`s can be created. Then producer can ask consumers to update to new `event_version` ```ad-quote title: Postel's Law Be conservative in what you send and liberal in what you accept. ``` 6. Maintain a schema registry. 1. Producers can describe and annotate their events. Consumers can discover events. 7. Use an event broker. 1. Should validate incoming events against schemas. 2. Should be able to query consumers for events. 8. Use event-supporting APIs. 1. Events usually tell a fact about a given entity: "BikeReturned", "OrderCreated", or "InvoicePaid". 2. Perhaps include URL to get more details about the underlying entity. 3. Evolve your events. 1. Add more details if necessary so consumers do not need to hit the producer too frequently. 2. Include: - Relevant details - Entity id - Exclude data that may become invalid (like the number of items in stock) 9. Use the storage-first pattern. 1. Helps to deduplicate or achieve idempotency. 10. Trace your events. ## Conclusion Events are always part of a larger, evolving system. Design your events for that system, not the local service producing those events. --- Created: 2023-05-02 22:40