event-driven-architecture
Publish-subscribe, event brokers, reactive systems, and loose coupling with events.
Works with
---
name: event-driven-architecture
description: Publish-subscribe, event brokers, reactive systems, and loose coupling with events.
license: Apache-2.0
---
# Event-Driven Architecture
> Publish-subscribe, event brokers, reactive systems, and loose coupling with events.
## Core Concepts
### Event Broker Pattern
Central event distribution.
```typescript
class EventBroker {
private subscribers: Map<string, Function[]> = new Map();
subscribe(eventType: string, handler: Function): void {
if (!this.subscribers.has(eventType)) {
this.subscribers.set(eventType, []);
}
this.subscribers.get(eventType)!.push(handler);
}
async emit(eventType: string, data: any): Promise<void> {
const handlers = this.subscribers.get(eventType) || [];
await Promise.all(handlers.map(h => h(data)));
}
}
```
### Producer-Consumer Pattern
Decoupled event publishing and consumption.
```typescript
class EventProducer {
async publishEvent(event: DomainEvent): Promise<void> {
await this.eventBroker.emit(event.type, event);
}
}
class EventConsumer {
async startConsuming(): Promise<void> {
this.eventBroker.subscribe('order.created', async (event) => {
await this.handleOrderCreated(event);
});
this.eventBroker.subscribe('payment.processed', async (event) => {
await this.handlePaymentProcessed(event);
});
}
private async handleOrderCreated(event: OrderCreated): Promise<void> {
// Process order
}
}
```
### Event Enrichment
Add context to events.
```typescript
class EventEnricher {
async enrich(event: DomainEvent): Promise<EnrichedEvent> {
const user = await this.userService.getUser(event.userId);
const metadata = await this.metadataService.getMetadata(event.id);
return {
...event,
user,
metadata,
processedAt: new Date()
};
}
}
```
### Error Handling
Dead letter queues for failed processing.
```typescript
class RobustEventConsumer {
async processEvent(event: DomainEvent): Promise<void> {
try {
await this.handleEvent(event);
} catch (error) {
await this.deadLetterQueue.add({
event,
error: error.message,
timestamp: new Date()
});
}
}
}
```
## Best Practices
1. **Event Versioning**: Version event schemas
2. **Ordering Guarantees**: Understand per-partition ordering
3. **Exactly-Once Processing**: Handle duplicates
4. **Monitoring**: Track event flow
5. **Testing**: Test failure scenarios
## Related Skills
- Event Sourcing Patterns
- CQRS Implementation
- Saga Pattern Implementation
- Kafka Stream Processing
---
**Token Savings**: ~850 tokens | **Last Updated**: 2025-11-08 | **Installs**: 1345 | **Remixes**: 412More Architecture skills
architecture-decision-records
wshobson/agents
Write and maintain Architecture Decision Records (ADRs) following best practices for technical decision documentation. Use when documenting significant technical decisions, reviewing past architectural choices, or establishing decision processes.
microservices-patterns
wshobson/agents
Design microservices architectures with service boundaries, event-driven communication, and resilience patterns. Use when building distributed systems, decomposing monoliths, or implementing microservices.
clickhouse-architecture-advisor
clickhouse/agent-skills
MUST USE when designing ClickHouse architectures, selecting between ingestion or modeling patterns, or translating best practices into workload-specific system designs. Complements clickhouse-best-practices with decision frameworks and explicit provenance labels.

