Skip to main content
KaireonAI separates business logic from infrastructure through a set of TypeScript interfaces (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 backends support graceful shutdown. On a termination signal, the platform closes connections cleanly so in-flight requests finish. Switching a backend takes effect on restart — set the environment variable and roll the deployment.

Interaction Store

The interaction store persists decision history, customer interactions, impressions, outcomes, and conversion data. It powers the Customer Viewer 360, attribution, and analytics.
Adapter: pg-interaction-store.tsThe default. Stores interactions in the same PostgreSQL database as the rest of the platform. Zero additional infrastructure.
At high volumes, interaction rows grow fast. Consider moving to DynamoDB or Scylla when you exceed 10K decisions/day or when interaction queries start affecting OLTP performance.

Event Bus

The event bus handles asynchronous event routing for decision events, model update notifications, pipeline triggers, and real-time streaming. Every backend supports the same operations: publishing events to a topic, subscribing consumers to receive them, and shutting down cleanly on termination.
Adapter: redis-events.tsUses your existing Redis instance for lightweight pub/sub messaging. Simple, no additional infrastructure.
Redis Pub/Sub is fire-and-forget — messages are lost if no subscriber is connected. For production workloads requiring durability and replay, use Kafka, MSK, or Kinesis.

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.
Adapter: pg-search.tsUses PostgreSQL’s built-in tsvector full-text search. No additional infrastructure needed.

Cache

Redis is used for caching enrichment data, sliding-window rate limiting, session storage, circuit breaker state, and background job queues. The cache layer supports standard read, write, and delete operations plus a cache-aside helper that fetches and stores a value in one call when the key is missing.
The cache adapter works with any Redis-compatible endpoint:
  • 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).
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)

All defaults. No additional services beyond PostgreSQL and optionally Redis.
Lean AWS deployment using managed services with pay-per-use pricing.
Higher throughput with dedicated event streaming and search infrastructure.
Maximum throughput with dedicated high-performance backends.

Adding a Custom Backend

Every infrastructure concern is behind a TypeScript interface. To add your own implementation:
1

Implement the backend contract

Add a new adapter alongside the existing infrastructure adapters. Each backend type has a small contract to satisfy:
  • Interaction store — record an event, fetch interaction summaries, and shut down cleanly.
  • Event bus — publish events to a topic, subscribe consumers, and shut down cleanly.
  • Search index — run a search query, index a document, and shut down cleanly.
  • Cache — get, set, and delete keys, fetch-or-populate in one call, health-check the connection, and shut down cleanly.
2

Register in the container

Add a new case to the corresponding factory function in container.ts:
3

Set the environment variable

4

Deploy

Restart the application. The container picks up the new env var and instantiates your implementation. Zero changes in business logic, API routes, or decision flow engine.