Skip to content

Sagas

INFO

}> Backend Orchestration Sagas are executed entirely within the backend infrastructure (Worker Services). They ensure data consistency across the Primary Database and Analytics Database when a single API request involves multiple logical steps.

Campaign Creation Saga

Multi-step orchestration for creating fundraising campaigns

When a user POSTs to /api/v1/fundraisers, the CampaignCreationSaga orchestrates the following steps:

Step :

Saga State Management

Saga state is tracked in the Events Database tables:

saga_instances Table

typescript
interface SagaInstance {
  id: uuid;
  saga_type: string;           // 'campaign_creation'
  aggregate_id: uuid;           // Campaign ID
  status: 'pending' | 'completed' | 'failed' | 'compensating';
  current_step: number;
  data: jsonb;                  // Saga context data
  error_message?: string;
  created_at: timestamp;
  updated_at: timestamp;
  completed_at?: timestamp;
}

Failure Handling & Compensation

When a saga step fails, the system automatically triggers compensation to rollback changes:

typescript
// Example: Campaign creation fails at step 3
Saga Execution Flow:
1. ✅ Validate Slug → Success
2. ✅ Create Campaign → Success (campaign ID: abc-123)
3. ❌ Update User Role → Failure (database constraint violation)

Compensation Flow (Automatic):
3. ⏪ Update User Role → N/A (nothing to compensate)
2. ⏪ Create Campaign → Soft delete campaign abc-123
1. ⏪ Validate Slug → N/A (validation only)

Final State:
- Saga status: 'failed'
- Campaign: Soft deleted with deleted_at timestamp
- User: Remains in previous role
- System Consistency: Maintained

INFO

}> Admin Dashboard Integration Super admins can monitor saga execution, failed steps, and compensation history through the Event Monitoring dashboard at /admin/event-monitoring.

Built with VitePress