RFC-025: Pattern SDK Architecture
Summary
Define the Pattern SDK architecture with clear separation between:
- Pattern Layer: Complex business logic implementing data access patterns (Multicast Registry, Session Store, CDC, etc.)
- Backend Driver Layer: Shared Go drivers and bindings for all backend systems
- Concurrency Primitives: Reusable Go channel patterns for robust multi-threaded pattern implementations
Key Insight: The pattern layer is where the innovation happens. Patterns are not simple "plugins" - they are sophisticated compositions of multiple backends with complex multi-threaded business logic solving real distributed systems problems.
Motivation
Why "Pattern" not "Plugin"?
"Plugin" undersells the complexity and innovation:
- ❌ Plugin: Suggests simple adapter or wrapper
- ✅ Pattern: Captures the sophistication and composition
Patterns are architectural solutions:
Pattern: Multicast Registry
├── Business Logic: Identity registration, metadata enrichment, multicast publish
├── Backend Composition:
│ ├── Registry Backend (KeyValue with Scan) - stores identities
│ ├── Messaging Backend (PubSub) - delivers multicasts
│ └── Durability Backend (Queue) - persists events
├── Concurrency: Worker pool for fan-out, circuit breakers for backends
└── Innovation: Same client API works with Redis+NATS, Postgres+Kafka, DynamoDB+SNS
This is not a "plugin" - it's a distributed pattern implementation.
Current Problem
Without clear SDK architecture:
- Code Duplication: Each pattern reimplements worker pools, circuit breakers, backend connections
- Inconsistent Patterns: No standard way to implement fan-out, bulkheading, retry logic
- Backend Coupling: Patterns tightly coupled to specific backend implementations
- No Reuse: Redis driver written for one pattern can't be used by another
Design Principles
1. Pattern Layer is the Star
Patterns solve business problems:
- Multicast Registry: Service discovery + pub/sub
- Session Store: Distributed state management
- CDC: Change data capture and replication
- Saga: Distributed transaction coordination
Patterns compose backends to implement solutions.
2. Backend Drivers are Primitives
Backend drivers are low-level:
// Backend driver = thin wrapper around native client
type RedisDriver struct {
client *redis.ClusterClient
}
func (d *RedisDriver) Get(ctx context.Context, key string) (string, error) {
return d.client.Get(ctx, key).Result()
}
Patterns use drivers to implement high-level operations:
// Pattern = business logic using multiple drivers
type MulticastRegistryPattern struct {
registry *RedisDriver // KeyValue backend
messaging *NATSDriver // PubSub backend
workers *WorkerPool // Concurrency primitive
}
func (p *MulticastRegistryPattern) PublishMulticast(event Event) error {
// Step 1: Get subscribers from registry
subscribers, err := p.registry.Scan(ctx, "subscriber:*")
// Step 2: Fan-out to messaging backend via worker pool
return p.workers.FanOut(subscribers, func(sub Subscriber) error {
return p.messaging.Publish(sub.Topic, event)
})
}
3. Concurrency Primitives are Reusable
Patterns need robust multi-threading:
- Worker pools for parallel operations
- Circuit breakers for fault tolerance
- Bulkheads for resource isolation
- Pipelines for stream processing
SDK provides battle-tested implementations.
Architecture
Three-Layer Stack
┌──────────────────────────────────────────────────────────────────┐
│ PATTERN LAYER │
│ (Complex Business Logic) │
│ │
│ ┌──────────────────┐ ┌───────────── ─────┐ ┌───────────────┐ │
│ │ Multicast │ │ Session Store │ │ CDC Pattern │ │
│ │ Registry Pattern │ │ Pattern │ │ │ │
│ │ │ │ │ │ │ │
│ │ - Register │ │ - Create │ │ - Capture │ │
│ │ - Enumerate │ │ - Get/Set │ │ - Transform │ │
│ │ - Multicast │ │ - Replicate │ │ - Deliver │ │
│ └──────────────────┘ └──────────────────┘ └───────────────┘ │
└────────────────────────────┬─────────────────────────────────────┘
│
Uses concurrency primitives + backend drivers
│
┌────────────────────────────▼─────────────────────────────────────┐
│ CONCURRENCY PRIMITIVES │
│ (Reusable Go Patterns) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Worker Pool │ │ Fan-Out │ │ Pipeline │ │
│ │ │ │ │ │ │ │
│ │ - Dispatch │ │ - Broadcast │ │ - Stage │ │
│ │ - Collect │ │ - Gather │ │ - Transform │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Circuit │ │ Bulkhead │ │ Retry │ │
│ │ Breaker │ │ │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└────────────────────────────┬─────────────────────────────────────┘
│
Uses backend drivers
│
┌────────────────────────────▼─────────────────────────────────────┐
│ BACKEND DRIVER LAYER │
│ (Shared Go Clients + Interface Bindings) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Redis Driver │ │ Postgres │ │ Kafka Driver │ │
│ │ │ │ Driver │ │ │ │
│ │ - Get/Set │ │ │ │ - Produce │ │
│ │ - Scan │ │ - Query │ │ - Consume │ │
│ │ - Pub/Sub │ │ - Subscribe │ │ - Commit │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ NATS Driver │ │ ClickHouse │ │ S3 Driver │ │
│ │ │ │ Driver │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└──────────────────────────────────────────────────────────────────┘
Pattern SDK File Structure
pattern-sdk/
├── README.md # SDK overview
├── go.mod # Go module definition
│
├── patterns/ # PATTERN LAYER (innovation spotlight)
│ ├── multicast_registry/ # Multicast Registry pattern
│ │ ├── pattern.go # Main pattern implementation
│ │ ├── registry.go # Identity registration logic
│ │ ├── multicast.go # Multicast publish logic
│ │ ├── config.go # Pattern configuration
│ │ └── pattern_test.go # Pattern tests
│ │
│ ├── session_store/ # Session Store pattern
│ │ ├── pattern.go # Distributed session management
│ │ ├── replication.go # Cross-region replication
│ │ ├── sharding.go # Consistent hashing
│ │ └── pattern_test.go
│ │
│ ├── cdc/ # Change Data Capture pattern
│ │ ├── pattern.go # CDC implementation
│ │ ├── capture.go # Change capture logic
│ │ ├── transform.go # Event transformation
│ │ └── pattern_test.go
│ │
│ └── saga/ # Saga pattern (future)
│ └── pattern.go
│
├── concurrency/ # CONCURRENCY PRIMITIVES
│ ├── worker_pool.go # Worker pool pattern
│ ├── fan_out.go # Fan-out/fan-in
│ ├── pipeline.go # Pipeline stages
│ ├── circuit_breaker.go # Circuit breaker
│ ├── bulkhead.go # Bulkhead isolation
│ ├── retry.go # Retry with backoff
│ └── concurrency_test.go
│
├── drivers/ # BACKEND DRIVER LAYER
│ ├── redis/ # Redis backend driver
│ │ ├── driver.go # Redis driver implementation
│ │ ├── cluster.go # Cluster support
│ │ ├── pubsub.go # Redis Pub/Sub
│ │ ├── bindings.go # Interface bindings
│ │ └── driver_test.go