← Back to Archive
Media / GameFi / Interactive TV Case Study

CTV (Gran Hermano)

The official Web3-integrated trivia companion app for Gran Hermano Argentina.

NestJS MongoDB Web3Auth React Redux Toolkit Ethers.js

Architecture Overview

A monolithic NestJS backend designed for burst traffic, which held up through live TV traffic spikes. It uses advanced MongoDB Aggregation Pipelines to calculate 'Time-Windowed' question availability relative to the server clock, ensuring all viewers see the same question at the exact same moment without race conditions.

The Challenges

Invisible Web3 Onboarding

Problem

TV viewers will not write down a 12-word seed phrase. We needed a way to give them an Ethereum wallet for rewards without breaking the 'Web2' UX.

Solution

Integrated Web3Auth's 'No-Modal' SDK. We authenticate users via standard OAuth (Google), then cryptographically derive an Ethereum private key from their OAuth token on the client side. The backend verifies the JWT against Web3Auth's JWKS, ensuring the wallet address matches the social identity without ever storing private keys.

web3-auth.guard.ts

Time-Synced State Aggregation

Problem

Trivia questions had to unlock and expire in perfect sync with the live TV feed. Polling the database for 'Current Question' at scale is expensive.

Solution

Engineered a temporal MongoDB Aggregation Pipeline. Instead of simple reads, we use `$switch` logic within the query to compute the `status` (Live, Pending, Expired) dynamically based on `$$NOW` (Server Time). This allows us to cache the result heavily while maintaining precise time-window enforcement.

trivia.service.ts

Atomic Game State Machine

Problem

Users can Answer, Hint, Skip, or Use Lifelines. Handling these mutually exclusive actions under high concurrency often leads to 'Double Spending' (e.g., using a lifeline twice).

Solution

Implemented a Discriminated Union Event Handler. Every user interaction is treated as an atomic `GameEvent`. We use MongoDB `upsert` with conditional logic (Optimistic Locking) to validate the transition state (e.g., `IF status == 'unanswered' THEN set 'answered'`) in a single atomic DB operation.

trivia-event.service.ts