A high-performance full-stack prototype designed to sanitize user video interaction interfaces, enforce strict visual attention policies using low-level browser APIs, and ingest telemetry data under aggressive burst traffic using a custom memory-bounded token bucket architecture.
This system is decoupled into two hyper-specialized layers containerized with Docker Compose:
- Frontend (Next.js / TypeScript): A zero-distraction layout utilizing a dual-layer tracking hook powered by the browser's native Page Visibility API and Intersection Observer API. It batches UX telemetry exceptions dynamically over a sliding 5-second window.
- Backend (Node.js / Express): A lightweight state machine that implements a raw, mathematical Token Bucket Rate Limiter directly inside the application run loop memory to protect telemetry ingestion routes against DDoS or faulty client loop vectors.
- Decision: Implemented an in-memory
Maptracking token bucket states inside application memory. - Trade-Off: While an in-memory map introduces a statelessness problem if scaled across multi-region serverless infrastructure (like Vercel functions), it provides sub-millisecond execution speeds with zero network round-trip overhead. For the production environment on Render, we deploy the backend as a single persistent Web Service process, preserving the memory layer reliably while keeping compute overhead to an absolute minimum.
-
Decision: Buckets calculate token accumulation lazily using timestamps during the request lifecycle (
Date.now() - this.lastRefill). -
Trade-Off: Running a continuous background thread or interval loop to refill client buckets would create an active CPU burden that scales linearly ($O(N)$) with the number of connected users. The lazy time-delta calculation shifts the computation entirely to
$O(1)$ at the exact millisecond a request is received, ensuring maximum server scalability.
- Decision: Prioritized
sendBeaconfor the 5-second queue flushes, falling back to traditional asynchronous fetch pipelines only when unsupported. - Trade-Off: Standard HTTP POST requests are often canceled by modern browsers if a user suddenly closes the tab or navigates away.
navigator.sendBeacontransmits the payload asynchronously over a background transport layer, ensuring that critical engagement data is successfully delivered even during ungraceful app exits, without impacting page unload performance.
- Decision: Configured Next.js with
output: 'export'to build as a purely static asset distribution for deployment. - Trade-Off: By omitting Server-Side Rendering (SSR), we remove the need for a live Node server pool for the UI. The frontend compiles down to atomic HTML, CSS, and JS, allowing it to be hosted on global edge networks permanently for free. It is fully decoupled from the backend and completely immune to free-tier "cold start" sleep delays.
Ensure you have Docker and Docker Compose installed on your machine.
- Clone the repository and navigate to the project directory:
cd ZeeDeeEngine