Product · SaaS · AI//2026

AutoAffiliate

AI video generation SaaS with hybrid licensing & concurrency locks.

Engineering Role
Lead Full-Stack Engineer & Product Architect
Delivery Timeline
Commercial Production Release
Architectural Stack
Next.js 14, TypeScript, PostgreSQL (Auth & RLS)
Release Status
ACTIVE IN PROD
Inspect Live System ↗
AutoAffiliate Pipeline · Session Guard & Credit Ledger
ACTIVE · PROTECTED MULTI-DEVICE SESSION
P99 LATENCY
<240ms
THROUGHPUT
Automated Queue Dispatch
ACTIVE DAG NODES
6
ALLOC BUFFER POOL
0 bytes/op
DAG Pipeline Execution Mesh (Real-time Wire State):
Session Device Fingerprint Guard12ms · COMPLETED
Credit Balance Ledger Check4.8ms · COMPLETED
Video Script & Asset Parsing820ms · ACTIVE
Background Render Queue Dispatch180ms · PENDING
Credit Deduction & State Commit6.2ms · PENDING
[16:20:12.401] [AUTH] Verified active user session: device_1=mobile device_2=desktop (2/2 allowed)
[16:20:12.440] [LEDGER] User credit balance: 48 units (Debit request: 2 units)
[16:20:13.290] [RENDER] Dispatched video batch #VF-492 to automated AI rendering pipeline
[16:20:13.310] [COMMIT] Ledger updated in 6.2ms (Zero-leak financial state)

The System Bottleneck & Problem Statement

Digital marketing affiliates needed automated short-form video generation to promote affiliate products. However, SaaS platforms either charged expensive monthly subscriptions that users abandoned, or suffered account-sharing abuse where 10+ users pooled money to exploit a single account.

Architected Solution & Execution Mechanics

Architected a hybrid business model: users purchase a lifetime software license for the core workflow, and consume pay-as-you-go credit tokens for cloud AI video rendering. Protected server infrastructure by enforcing a strict 2-device concurrency session limit.

INTERACTIVE ARCHITECTURE FLOW (CLICK NODE TO INSPECT SPEC):
Next.js App Router & Tailwind

Affiliate Dashboard

Zero-lag interface with credit balance telemetry and live video previews.

Core Architecture Implementation

Production-grade architecture implementation powering AutoAffiliate:

src/lib/sessionGuard.ts
import { db } from '@/lib/db';

// Strict Dual-Device Concurrency Session Guard
export async function enforceMaxTwoDevices(userId: string, currentDeviceId: string): Promise<boolean> {
  const { data: activeSessions, error } = await db
    .from('user_active_sessions')
    .select('device_id, last_heartbeat')
    .eq('user_id', userId)
    .gt('last_heartbeat', new Date(Date.now() - 5 * 60 * 1000).toISOString())
    .order('last_heartbeat', { ascending: true });

  if (error || !activeSessions) return false;

  const deviceExists = activeSessions.some(s => s.device_id === currentDeviceId);
  if (deviceExists) {
    // Update heartbeat of current device
    await db
      .from('user_active_sessions')
      .update({ last_heartbeat: new Date().toISOString() })
      .eq('device_id', currentDeviceId);
    return true;
  }

  // If already at 2 devices, evict oldest session
  if (activeSessions.length >= 2) {
    const oldestDevice = activeSessions[0].device_id;
    await db
      .from('user_active_sessions')
      .delete()
      .eq('device_id', oldestDevice);
  }

  // Register new device session
  await db
    .from('user_active_sessions')
    .insert({
      user_id: userId,
      device_id: currentDeviceId,
      last_heartbeat: new Date().toISOString()
    });

  return true;
}

Key Engineering Responsibilities

[01]

Engineered credit ledger database schema with ACID atomic transactions to prevent double-spending.

[02]

Built session concurrency middleware detecting and limiting simultaneous logins to 2 active devices.

[03]

Created a unified billing & top-up workflow with automated credit disbursement upon payment.

[04]

Designed high-density dark UI with intuitive credit meters and video generation status monitors.

Non-Trivial Trade-Offs & Decisions

CASE // 01

Preventing Double-Spending of Video Credits

System Friction: When users opened multiple tabs and clicked "Render" simultaneously, asynchronous requests read the old balance before writing the debit, allowing free video generations.

Architectural Decision: Migrated balance checks to PostgreSQL stored procedures using `SELECT FOR UPDATE` row-level locks, making balance verification and debit execution completely atomic.

Measured Outcome: Zero credit leaks across thousands of simulated parallel requests.

Quantified Production Telemetry

Dual-Device
Session Concurrency Lock
100%
Credit Ledger Integrity
<250ms
Auth & Quota Validation
Automated
Top-Up Reconciliation
SUBSEQUENT CASE STUDY
Joyzone Electronics

A high-throughput electronic components marketplace with a 5-step transactional checkout, geocoding address verification, and 10-module inventory control.

Next Case Study →