Engine Architecture & Data Flow
Every request GN-Apex receives is sorted before it's processed. Transactional work runs through a control plane built for correctness; telemetry runs through a sentry built for volume. Here's how the two stay out of each other's way.
“Actix-web zero-cost abstractions combined with Redis stream buffers ensure constant single-digit ingestion latency.”
Topological Overview
The platform routes traffic based on workload characteristics: heavy transactional workloads (Auth, Schemas, Billing, CRM) are handled by the NestJS Control Plane, while telemetry and RUM packets are directed to the Rust Analytics Sentry. Neither engine blocks on the other — a spike in one never degrades the other's latency.
The Dual-Engine Model
NestJS Core (Port 3001)
Governs business logic: RBAC authorization, custom schemas, billing transactions, WebPush notifications, and communication dispatchers.
Rust Sentry (Port 3002)
Built for massive throughput: validates tokens, checks rate limits, enriches GeoIP/ASN, and writes to Redis Streams in < 3ms.
PostgreSQL Truth Layer
ACID-compliant storage for users, organizations, custom domain certificates, invoices, and CRM address books.
MongoDB Event Vault
High-density BSON storage: holds billions of interaction events with N → 1 session aggregation to avoid lock contention.
Data Storage Tiers
Storage is strictly partitioned to guarantee high durability, sub-second query performance, and cost efficiency:
| Parameter | Type | Requirement | Description |
|---|---|---|---|
| PostgreSQL (Prisma) | Relational ACID | Required | Holds transactional records: Users, Project permissions, Invoices, Wallets, CRM contacts, and Domains. |
| MongoDB (BSON) | Document Store | Required | Written exclusively by Rust: raw events, session documents, identities, and daily project summaries. |
| Redis Streams | In-Memory FIFO | Required | High-speed ingestion buffer (`MAXLEN ~1M`), BullMQ job queues, live active user counters, and cached queries. |
| Cloudflare R2 / S3 | Blob Object Store | Required | Stores optimized WebP/AVIF media, H.264 video streams, encrypted KYC documents, and compiled Next.js ISR bundles. |
The High-Speed Write Path
When an analytics packet hits POST /api/collect, the Rust engine moves it through four phases — each one handing off to the next without waiting for it to finish:
Token & Rate Limiting
Ingests the API key and evaluates client IP limits against an in-memory token bucket (L1) and Redis distributed limiters (L2).
Stream Buffering
Directly appends the packet into Redis Stream (events_stream) and returns HTTP 202 Accepted within 2–5ms.
Async Enrichment Workers
Background worker threads consume the stream, resolve GeoIP2/ASN metadata, parse User-Agent headers, run ML outlier scoring, and batch-write to MongoDB.
Real-time WS Fan-Out
Publishes the event to Redis Pub/Sub channels (live_events:*) to update live dashboard clients over WebSockets.
Circuit Breakers & Fault Tolerance
CLOSED, OPEN, HALF_OPEN). If network calls fail 5 times consecutively, traffic is temporarily halted for 30 seconds, and local cached data is served seamlessly to prevent cascading server crashes.