Skip to main content

Event Bus

The event bus is the backbone of PLATFORMA's inter-service communication. All state changes are published as events, enabling loose coupling between services and supporting async workflows.

Architecture

PLATFORMA uses NATS JetStream as the event bus, providing:

  • At-least-once delivery — Events are persisted and redelivered on failure
  • Consumer groups — Multiple instances of a service share the workload
  • Replay — Historical events can be replayed for recovery or debugging
  • Filtering — Consumers subscribe to specific event patterns

Event Structure

All events follow a consistent envelope format:

{
  "id": "evt_abc123",
  "type": "order.provisioned",
  "version": "1.0",
  "tenant_id": "ten_xyz789",
  "timestamp": "2026-03-15T10:05:22Z",
  "source": "provisioning-service",
  "data": {
    "order_id": "ord_xyz789",
    "resources": [
      { "id": "res_vm_001", "type": "virtual_machine", "status": "running" }
    ]
  },
  "metadata": {
    "correlation_id": "req_abc123",
    "trace_id": "trace_def456"
  }
}

Event Categories

Order Events

EventPublished When
order.createdNew order submitted
order.validatedOrder passes validation
order.processingProvisioning workflow started
order.provisionedAll resources ready
order.failedProvisioning failed
order.cancelledOrder cancelled

Resource Events

EventPublished When
resource.createdResource provisioned
resource.updatedResource configuration changed
resource.status_changedResource status transition
resource.deletedResource terminated

Billing Events

EventPublished When
invoice.generatedInvoice created for billing period
invoice.paidPayment received
invoice.overduePayment past due date
usage.recordedUsage data point recorded
usage.threshold_reachedUsage nearing limit

Consumer Patterns

Direct Processing

A service directly processes events to update its own state:

order.created → Billing Service → Create subscription record

Event Choreography

Multiple services react to the same event independently:

order.provisioned → Billing Service  → Activate subscription
                  → Notification Svc → Send welcome email
                  → Monitoring Svc   → Configure alerts

Saga Pattern

Long-running workflows coordinate across services:

order.created → Provisioning → resource.created → DNS Setup → dns.configured → Monitoring → order.provisioned

If any step fails, compensating events undo previous steps.

Use correlation IDs to trace an event through the entire system. Every event in a workflow shares the same correlation_id, making debugging straightforward.