lib/infra/interfaces.ts) and a dependency injection container (lib/infra/container.ts). Each infrastructure concern — interaction storage, event publishing, search, caching, and logging — has a default implementation that works out of the box and one or more alternatives that you can activate with a single environment variable.
No code changes are required to switch backends. Set the env var, restart, and the container instantiates the correct adapter as a singleton.
All infrastructure singletons support graceful shutdown. Call
shutdownInfra() on SIGTERM to close connections cleanly. You can also call resetInfra() to tear down and re-initialize all backends when configuration changes at runtime.Interaction Store
The interaction store persists decision history, customer interactions, impressions, outcomes, and conversion data. It powers the Customer Viewer 360, attribution, and analytics.- PostgreSQL (default)
- DynamoDB
- Scylla / Cassandra
- AWS Keyspaces
Adapter:
pg-interaction-store.tsThe default. Stores interactions in the same PostgreSQL database as the rest of the platform. Zero additional infrastructure.| Best for | Development, small deployments, less than 10K decisions/day |
| Config | No additional config — uses DATABASE_URL |
| Cost | Included with your existing database |
Event Bus
The event bus handles asynchronous event routing for decision events, model update notifications, pipeline triggers, and real-time streaming. All implementations satisfy theEventPublisher interface with publish(), subscribe(), and disconnect() methods.
- Redis Pub/Sub (default)
- Kafka / Redpanda
- AWS MSK
- Kinesis
- EventBridge
Adapter:
redis-events.tsUses your existing Redis instance for lightweight pub/sub messaging. Simple, no additional infrastructure.| Best for | Development, staging, low-to-medium throughput |
| Config | Uses REDIS_URL — no additional env vars |
| Cost | Included with your Redis instance |
Search Index
The search index powers full-text search across offers, categories, decision flows, and other platform entities. It also drives the global search bar and analytics queries.- PostgreSQL FTS (default)
- OpenSearch
Adapter:
pg-search.tsUses PostgreSQL’s built-in tsvector full-text search. No additional infrastructure needed.| Best for | Under 1M records, simple search queries |
| Config | Uses DATABASE_URL — no additional env vars |
| Cost | Included with your existing database |
Cache
Redis is used for caching enrichment data, sliding-window rate limiting, session storage, circuit breaker state, and BullMQ job queues. TheCacheStore interface provides get, set, del, and getOrFetch (cache-aside pattern) methods.
- Redis OSS — local development or self-hosted
- Amazon ElastiCache — managed Redis on AWS
- Upstash Redis — serverless Redis with per-request pricing
- Dragonfly — Redis-compatible, multi-threaded drop-in replacement
Redis is optional in development (the platform falls back to in-process defaults), but required for production. Without Redis, rate limiting, enrichment caching, and background job processing will not function correctly.
Logging
KaireonAI uses Winston for structured JSON logging. The default console transport works for development and containerized deployments where log aggregation happens at the orchestrator level (e.g., CloudWatch Container Insights, Datadog Agent).- Console (default)
- CloudWatch
Structured JSON logs written to stdout/stderr. Works with any log aggregation system that reads container output.
Choosing Your Stack
Use these reference architectures as a starting point. Every backend is independently swappable, so you can mix and match based on your requirements.Development (zero config)
Development (zero config)
All defaults. No additional services beyond PostgreSQL and optionally Redis.
| Concern | Backend | Config |
|---|---|---|
| Interactions | PostgreSQL | Default |
| Events | Redis Pub/Sub | REDIS_URL |
| Search | PostgreSQL FTS | Default |
| Cache | Redis | REDIS_URL |
| Logging | Console | Default |
| Estimated cost | $0 (local) |
Startup on AWS (~$50-100/mo)
Startup on AWS (~$50-100/mo)
Lean AWS deployment using managed services with pay-per-use pricing.
| Concern | Backend | Config |
|---|---|---|
| Interactions | PostgreSQL | Default |
| Events | EventBridge | EVENT_PUBLISHER=eventbridge |
| Search | PostgreSQL FTS | Default |
| Cache | Upstash Redis | REDIS_URL=rediss://... |
| Logging | CloudWatch | Via platform settings |
| Estimated cost | $50-100/mo |
Growth on AWS (~$500-1K/mo)
Growth on AWS (~$500-1K/mo)
Higher throughput with dedicated event streaming and search infrastructure.
| Concern | Backend | Config |
|---|---|---|
| Interactions | DynamoDB | INTERACTION_STORE=dynamodb |
| Events | MSK or Kafka | EVENT_PUBLISHER=msk |
| Search | OpenSearch | SEARCH_INDEX=opensearch |
| Cache | ElastiCache | REDIS_URL=rediss://... |
| Logging | CloudWatch | Via platform settings |
| Estimated cost | $500-1K/mo |
Enterprise (>$2K/mo)
Enterprise (>$2K/mo)
Maximum throughput with dedicated high-performance backends.
| Concern | Backend | Config |
|---|---|---|
| Interactions | Scylla | INTERACTION_STORE=scylla |
| Events | MSK | EVENT_PUBLISHER=msk |
| Search | OpenSearch | SEARCH_INDEX=opensearch |
| Cache | ElastiCache (cluster mode) | REDIS_URL=rediss://... |
| Logging | CloudWatch | Via platform settings |
| Estimated cost | $2K+/mo |
Adding a Custom Backend
Every infrastructure concern is behind a TypeScript interface. To add your own implementation:Implement the interface
Create a new file in
src/lib/infra/ that implements one of:InteractionStore—recordEvent(),getSummaries(),disconnect()EventPublisher—publish(),subscribe(),disconnect()SearchIndex—search(),index(),disconnect()CacheStore—get(),set(),del(),getOrFetch(),ping(),disconnect()