event-driven-architecture
Event-Driven Architecture
Domain events are the cleanest decoupling primitive in a Rails app.
Order#after_create_commit :publish_order_placedlets billing, notifications, and analytics react without knowing about each other. This skill covers what to emit, how, and where event-driven goes wrong (event sourcing for everything is usually wrong).
The opinion
Emit domain events for cross-cutting concerns (notifications, audit, analytics). Use the transactional outbox so events publish atomically with the business write. Distinguish domain events (what happened in your bounded context) from integration events (what you tell other services). Use
rails_event_storefor in-app event handling. Do NOT adopt event sourcing as the default — it's a powerful but expensive pattern.
Domain events vs integration events
| Domain event | Integration event | |
|---|---|---|
| Audience | Code inside your bounded context | Other services / downstream systems |
| Schema | Free to change | Versioned contract |
| Coupling | Loose internal | Hard external |
| Examples | OrderConfirmed, EmailVerified |
order.placed.v1, user.deleted.v1 |
| Transport | In-process pub/sub | Kafka / RabbitMQ |
Don't mix them. Internal domain events are private — change at will. Integration events are public APIs and follow the same compatibility rules as your HTTP API.