Polyglot Persistence & Domain Event Buses: Scaling Multi-Tenant SaaS
How we combine Hexagonal Architecture, Redis Streams/PubSub, MongoDB Beanie ODM, and PostgreSQL concurrency locking for real-time enterprise workloads.
No single database engine is optimal for every access pattern in a modern enterprise SaaS. Across Suite Aerya (conversational AI) and BrickTicket (real-time construction ERP & job costing), forcing vector search, ephemeral pub/sub state, and ACID financial ledgers into a single datastore creates immediate throughput bottlenecks.
1. The 3-Tier Polyglot Storage Topology
We separate storage strictly by latency and consistency guarantees:
- L1 Edge & Hot Cache (
Cloudflare KV / D1 & Redis Cache — 1.8ms hit): Tenant configuration, session tokens, and idempotency keys with strict TTL eviction. - L2 Event Backbone (
Redis Pub/Sub & Cloud Tasks — 4,820 msg/sec): Non-blocking domain events (OrderCostUpdated,AgentTurnCompleted,GanttScheduleShifted) fan out to asynchronous workers. - L3 System of Record (
PostgreSQL + MongoDB Atlas 3072d): Relational ACID transactions with optimistic concurrency control for BrickTicket financial job-costing ledgers, paired with document + vector collections via Beanie ODM for high-dimensional semantic retrieval.
2. Hexagonal Boundaries in Python 3.13 & TypeScript
By enforcing Hexagonal (Ports & Adapters) boundaries, domain services remain 100% agnostic of whether an event is dispatched over in-memory queues during unit tests, Redis Pub/Sub in staging, or Google Cloud Pub/Sub in production.