04. Analytics Sentry/Engine Architecture

Rust Analytics Sentry

The GN-Apex telemetry engine is a standalone daemon written in Rust (Actix-web). It ingests high-volume event streams, enriches metadata in memory, executes statistical bot detection, and broadcasts live dashboard telemetry.

INGESTION BENCHMARK
2.3ms
P95 Ingestion Latency

High-throughput stream processing with zero garbage collection pauses. Built to withstand massive traffic spikes.

Actix-web · Redis Streams · MongoDB
POST/api/collect

The Sentry Architecture

The engine operates on four decoupled layers designed to isolate ingress latency from heavy analytical computing:

INGESTION / REDIS

Stream FIFO Buffer

Appends events to Redis Streams with a 1,000,000 max length cap. Returns HTTP 202 in single-digit ms.

BOT SHIELD / ML

Anomaly Engine

Statistical Z-Score outlier detection, Haversine impossible-travel velocity, and Tor exit-node blocking.

STORAGE / BATCHING

N → 1 Deduplication

Aggregates 500 events across 50 sessions into single bulk MongoDB upserts, eliminating database pressure.

REALTIME / WEBSOCKET

Live Fan-Out

Subscribes to Redis Pub/Sub channels ('live_events:*') and multicasts telemetry to dashboard lobbies.

The High-Speed Write Path

When an event arrives at POST /api/collect, the daemon executes a non-blocking sequence:

  1. API Key Authentication: Validates public/secret tokens in memory using an LRU cache.
  2. Rate Limit Check: Evaluates client IP quotas against governor token buckets (L1) and Redis sliding windows (L2).
  3. Redis Stream Ingestion: Appends the packet to events_stream and immediately responds with HTTP 202 Accepted.

Asynchronous Enrichment

Background worker threads drain the stream and apply real-time enrichment:

ParameterTypeRequirementDescription
GeoIP2 & ASNMaxMind DBOptionalResolves Country, City, Coordinates, and Autonomous System Numbers (ISP/Hosting detection).
User-Agent ParserDashMap CacheOptionalExtracts OS, Browser, and Device category with in-memory lock-free caching for high concurrency.
B2B Lead ScoringFirmographicsOptionalCalculates commercial value (0-100 pts) based on corporate domain signals and sends Slack alerts for hot leads (≥70).
Behavioral AnalyticsHeuristicsOptionalIdentifies rage clicks (3+ clicks in 400px zone within 1000ms), dead clicks, and scroll depth milestones.

Dual Query Modes (Fast vs. Deep)

Query Strategy
Fast Mode (O(days)): Queries pre-aggregated project_summaries documents for instantaneous overview charts.
Deep Mode (O(events)): Executes full MongoDB aggregation pipelines across raw event collections for forensic breakdowns.