Skip to main content

Event-Driven Processing

Azotte uses event-driven architecture to enable real-time processing, loose coupling, and scalable system integration.

Architecture Overview

┌───────────────┐     ┌───────────────────────┐     ┌─────────────────┐
│ Event Producers │────▶│ Message Bus │────▶│ Event Consumers │
│ │ │ │ │ │
│• Subscription │ │• Apache Kafka │ │• Webhook Service │
│• Payment │ │• RabbitMQ │ │• Analytics │
│• Campaign │ │• Event Store │ │• Notifications │
│• Customer │ │• Message Routing │ │• Integrations │
└───────────────┘ └───────────────────────┘ └─────────────────┘

Event Types

Subscription Events

  • subscription.created - New subscription activated
  • subscription.updated - Subscription details changed
  • subscription.cancelled - Subscription cancelled
  • subscription.renewed - Subscription renewed
  • subscription.paused - Subscription temporarily paused
  • subscription.resumed - Subscription reactivated

Payment Events

  • payment.authorized - Payment successfully authorized
  • payment.captured - Payment captured/settled
  • payment.failed - Payment attempt failed
  • payment.refunded - Refund processed
  • payment.disputed - Chargeback/dispute initiated

Customer Events

  • customer.created - New customer registered
  • customer.updated - Customer profile changed
  • customer.deleted - Customer account deleted

Campaign Events

  • campaign.activated - Campaign went live
  • campaign.applied - Campaign applied to purchase
  • campaign.expired - Campaign reached end date

Event Schema

Standard Event Structure

{
"id": "evt_1234567890",
"type": "subscription.created",
"version": "1.0",
"timestamp": "2024-03-14T10:30:00Z",
"tenant_id": "tenant_123",
"correlation_id": "corr_abc123",
"data": {
"subscription": {
"id": "sub_1234567890",
"customer_id": "cus_1234567890",
"status": "active",
"bundle_id": "bundle_premium",
"price_id": "price_monthly_99"
}
},
"metadata": {
"source": "subscription-service",
"idempotency_key": "idem_xyz789"
}
}

Event Versioning

  • Semantic versioning for event schemas
  • Backward compatibility guarantees
  • Gradual migration strategies
  • Schema evolution support

Message Bus Infrastructure

Apache Kafka

  • Use Case: High-throughput event streaming
  • Benefits: Durability, scalability, ordering
  • Topics: Partitioned by tenant or event type

RabbitMQ

  • Use Case: Reliable message delivery
  • Benefits: Complex routing, delivery guarantees
  • Exchanges: Topic-based and direct routing

Event Store

  • Use Case: Event sourcing and audit trails
  • Benefits: Complete event history, replay capability
  • Storage: Append-only event logs

Processing Patterns

Publish-Subscribe

  • Multiple consumers for single event
  • Decoupled service communication
  • Fan-out event distribution
  • Independent consumer scaling

Event Sourcing

  • State derived from event history
  • Audit trail and compliance
  • Time-travel debugging
  • State reconstruction

CQRS (Command Query Responsibility Segregation)

  • Separate read and write models
  • Optimized query performance
  • Command validation and processing
  • Eventual consistency handling

Saga Pattern

  • Distributed transaction management
  • Compensating actions for failures
  • Long-running business processes
  • Cross-service coordination

Event Processing Guarantees

At-Least-Once Delivery

  • Events delivered at least once
  • Duplicate handling required
  • Higher reliability guarantee
  • Idempotency key usage

Exactly-Once Processing

  • Deduplication mechanisms
  • Idempotency enforcement
  • Higher complexity but cleaner semantics
  • Critical for financial transactions

Message Ordering

  • Per-partition ordering in Kafka
  • Global ordering where required
  • Timestamp-based sequencing
  • Causal consistency

Error Handling and Resilience

Retry Mechanisms

  • Exponential backoff strategies
  • Maximum retry limits
  • Dead letter queues
  • Circuit breaker patterns

Failure Recovery

  • Event replay capabilities
  • State reconstruction
  • Partial failure handling
  • Compensation workflows

Monitoring and Alerting

  • Event processing metrics
  • Lag monitoring
  • Error rate tracking
  • Performance dashboards

Integration Patterns

Webhook Delivery

  • HTTP-based event delivery
  • Retry and backoff logic
  • Signature verification
  • Filtering and routing

Stream Processing

  • Real-time event analytics
  • Complex event processing
  • Windowing operations
  • Stream joins and aggregations

Batch Processing

  • Periodic event processing
  • Bulk operations
  • Data warehouse integration
  • Historical analysis

Next Steps