1.8 KiB
1.8 KiB
ADR-0023: Event Bus Implementation
Status
Accepted
Context
The platform needs an event bus for:
- Module-to-module communication
- Decoupled event publishing
- Event sourcing (optional, future)
- Integration with external systems
Options considered:
- In-process channel-based bus - Simple, for development/testing
- Kafka - Production-grade, scalable
- RabbitMQ - Alternative message broker
- Redis pub/sub - Simple but less reliable
Decision
Support dual implementation with in-process primary, Kafka for production:
-
In-process bus (default):
- Channel-based implementation
- Used for development, testing, small deployments
- Simple, no external dependencies
-
Kafka bus (production):
- Full Kafka integration via
segmentio/kafka-go - Producer/consumer groups
- Configurable via environment (switch implementation)
- Full Kafka integration via
Rationale:
- In-process bus is simple for development
- Kafka provides production-grade reliability and scalability
- Interface abstraction allows swapping
- Modules don't need to know which implementation
- Can start simple and scale up
Consequences
Positive
- Simple for development (no Kafka needed)
- Scalable for production (Kafka)
- Flexible (can choose implementation)
- Modules are decoupled from implementation
Negative
- Two implementations to maintain
- Need to ensure interface covers both use cases
- Kafka adds infrastructure complexity
Implementation Notes
- Create
pkg/eventbus/eventbus.gointerface - Implement
internal/infra/bus/inprocess_bus.go(channel-based) - Implement
internal/infra/bus/kafka_bus.go(Kafka) - Select implementation via config
- Support both sync and async event publishing
- Handle errors gracefully (retry, dead letter queue)