A high-performance, enterprise-grade notification service that enables reliable event processing and notification delivery at scale. Perfect for applications that require robust event handling with advanced resilience mechanisms.
- Multi-Provider Support: Send notifications through various channels (email, SMS, push, etc.) with unified configuration
- Batch Processing: Efficiently bundle events for optimal performance and throughput
- Data Persistence: Optional persistent storage of events in a Data Lake for audit purposes and analytics
- Rate Limiting: Protect against overload through intelligent event processing throttling
- Resilience Mechanisms:
- Circuit breaker pattern to handle faulty providers
- Automatic retries for undelivered messages with exponential backoff
- Multi-Tenant Capability: Isolated resource management for different tenants
- Enterprise Features: Comprehensive monitoring, metrics, and configuration options
go get github.com/kopexa-grc/notifier
Requires Go 1.20 or later.
package main
import (
"context"
"time"
"github.com/kopexa-grc/notifier"
)
func main() {
// Create a new notification service with options
service, err := notifier.NewService(
notifier.WithMaxEventsPerMinute(100),
notifier.WithBatchSize(10),
notifier.WithCircuitBreakerEnabled(true),
notifier.WithRetryEnabled(true),
)
if err != nil {
panic(err)
}
// Notify organization-wide
service.NotifyOrganization(
context.Background(),
notifier.EventTypeInfo,
"Hello World!",
"organization-id",
[]string{"user-1", "user-2"},
)
// Close the service when done
defer service.Close()
}
The Notifier Service is implemented as a pipeline that receives events from various sources, processes them, and distributes them to configured providers. The architecture consists of these main components:
- Event Receiver: Accepts events and forwards them to the processor
- Rate Limiter: Limits the number of processed events per time unit
- Batch Processor: Groups events for efficient processing
- Provider Manager: Manages different notification channels
- Resilience Layer: Implements circuit breaker and retry mechanisms
- Data Lake: Optional persistent storage for events
Notifier uses Go's official golang.org/x/time/rate
package for rate limiting to protect your systems from overload:
// Create a notifier configuration with rate limiting
config := notifier.NotifierConfig{
MaxEventsPerMinute: 60, // 1 event per second
}
// Adjust rate limit at runtime
service.SetRateLimits(120, 0) // 2 events per second
Protection against cascading failures by temporarily disabling failed providers:
// Circuit Breaker configuration using options pattern
service, err := notifier.NewService(
notifier.WithCircuitBreakerEnabled(true),
notifier.WithCircuitBreakerMaxFailures(5),
notifier.WithCircuitBreakerTimeoutSec(60),
)
The Circuit Breaker operates in three states:
- Closed: Normal operation, requests pass through
- Open: After reaching failure threshold, all requests are rejected
- Half-open: After timeout, limited test requests are allowed
Automatic retry of failed events with exponential backoff strategy:
// Configure retry mechanism
service, err := notifier.NewService(
notifier.WithRetryEnabled(true),
notifier.WithMaxRetries(3),
notifier.WithRetryInitialDelaySec(5),
notifier.WithRetryMaxDelaySec(60),
notifier.WithRetryBackoffFactor(2.0),
)
Store events for audit, analysis or manual processing:
// Create a custom data lake implementation
type MyDataLake struct {
// implementation details
}
func (d *MyDataLake) Store(ctx context.Context, event notifier.BaseEvent) error {
// Store event implementation
}
// Additional required methods...
// Add data lake to service
service, err := notifier.NewService(
notifier.WithDatalake(&MyDataLake{}),
)
Option | Description | Default |
---|---|---|
MaxEventsPerMinute | Rate limiting cap | 100 |
BatchSize | Number of events per batch | 10 |
BatchTimeoutSeconds | Timeout for batch processing | 30 |
RetentionDays | Data retention period in days | 90 |
Option | Description | Default |
---|---|---|
CircuitBreakerEnabled | Enables circuit breaker pattern | false |
CircuitBreakerMaxFailures | Failures before tripping | 5 |
CircuitBreakerTimeoutSec | Reset timeout in seconds | 60 |
RetryEnabled | Enables retry mechanism | false |
MaxRetries | Maximum retry attempts | 3 |
RetryInitialDelaySec | Initial delay between retries (seconds) | 5 |
RetryMaxDelaySec | Maximum delay between retries (seconds) | 300 |
RetryBackoffFactor | Exponential backoff multiplier | 2.0 |
PersistFailedEvents | Store events after max retries | false |
Create custom notification providers by implementing the Provider interface:
type CustomProvider struct {
// provider fields
}
func (p *CustomProvider) Send(ctx context.Context, event notifier.BaseEvent) error {
// Implementation for sending notifications
return nil
}
func (p *CustomProvider) Name() string {
return "custom-provider"
}
// Register with service
service.RegisterProvider(&CustomProvider{})
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes using Conventional Commits format
- Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please read CONTRIBUTING.md for details on our code of conduct and development process.
This project is licensed under the BUSL-1.1 License - see the LICENSE file for details.