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 activatedsubscription.updated- Subscription details changedsubscription.cancelled- Subscription cancelledsubscription.renewed- Subscription renewedsubscription.paused- Subscription temporarily pausedsubscription.resumed- Subscription reactivated
Payment Events
payment.authorized- Payment successfully authorizedpayment.captured- Payment captured/settledpayment.failed- Payment attempt failedpayment.refunded- Refund processedpayment.disputed- Chargeback/dispute initiated
Customer Events
customer.created- New customer registeredcustomer.updated- Customer profile changedcustomer.deleted- Customer account deleted
Campaign Events
campaign.activated- Campaign went livecampaign.applied- Campaign applied to purchasecampaign.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
- Learn about Failover PSP Routing
- Understand Campaign Engine
- Explore Webhook Integration