# 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: 1. **In-process channel-based bus** - Simple, for development/testing 2. **Kafka** - Production-grade, scalable 3. **RabbitMQ** - Alternative message broker 4. **Redis pub/sub** - Simple but less reliable ## Decision Support **dual implementation** with **in-process primary, Kafka for production**: 1. **In-process bus (default)**: - Channel-based implementation - Used for development, testing, small deployments - Simple, no external dependencies 2. **Kafka bus (production)**: - Full Kafka integration via `segmentio/kafka-go` - Producer/consumer groups - Configurable via environment (switch implementation) **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.go` interface - 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)