Event Driven Architecture - pratchaya-maneechot/service-exchange GitHub Wiki

Event-Driven Architecture

Event Bus Implementation

Technology: Apache Kafka

Topic Naming Convention:

domain.entity.event
├── user.user.registered
├── user.user.verified
├── task.task.created
├── task.task.completed
├── payment.transaction.processed
├── payment.escrow.released
└── notification.message.sent

Key Event Flows

Task Creation Flow

sequenceDiagram
    participant Client
    participant TaskService
    participant LocationService
    participant NotificationService
    participant EventBus

    Client->>TaskService: POST /tasks
    TaskService->>EventBus: Publish TaskCreated
    EventBus->>LocationService: TaskCreated Event
    EventBus->>NotificationService: TaskCreated Event
    LocationService->>LocationService: Store location data
    NotificationService->>NotificationService: Notify nearby taskers
Loading

Task Assignment Flow

sequenceDiagram
    participant BiddingService
    participant TaskService
    participant PaymentService
    participant NotificationService
    participant EventBus

    BiddingService->>EventBus: Publish BidAccepted
    EventBus->>TaskService: BidAccepted Event
    EventBus->>PaymentService: BidAccepted Event
    EventBus->>NotificationService: BidAccepted Event
    TaskService->>TaskService: Update task status
    PaymentService->>PaymentService: Create escrow
    NotificationService->>NotificationService: Notify parties
Loading

Event Schema Management

Versioning Strategy:

  • Semantic versioning (major.minor.patch)
  • Backward compatibility for minor versions
  • Migration path for major changes

Example Evolution:

// Version 1.0
{
  "eventType": "TaskCreated",
  "version": "1.0",
  "taskId": "uuid",
  "title": "string"
}

// Version 1.1 (backward compatible)
{
  "eventType": "TaskCreated", 
  "version": "1.1",
  "taskId": "uuid",
  "title": "string",
  "priority": "normal" // new optional field
}
⚠️ **GitHub.com Fallback** ⚠️