Learnsignal · 2026 – present

Learnsignal LMS

Educational LMS platform providing course materials, billing, and automated exam grading for professional accounting students.

JWT claim
RLS policy
indexed read
PostgreSQL·Supabase·Next.js·Stripe·Claude

Problem

Row Level Security policies performed per-row table lookups against user_roles, triggering 49k-row sequential scans and driving admin dashboard queries to 3.4–4.5 seconds. Billing had a monolithic 1,156-line Stripe webhook handler and a PayPal race condition that caused duplicate charges (~$5.3k revenue impact). Manual exam grading created operational backlogs.

Approach

Rewrote 49 RLS policies across 28 tables to extract auth.jwt() ->> 'user_role' claims directly from session tokens, removing redundant joins to user_roles.

Decomposed the Stripe webhook handler into 4 single-responsibility endpoints. Added PostgreSQL transaction advisory locks (pg_advisory_xact_lock) for gapless invoice numbering. Re-engineered PayPal dunning to parse API issue names and apply 24-hour exponential backoff retries.

Engineered an automated exam-marking pipeline using Claude 3.5 Sonnet via the Anthropic Message Batches API (~$0.01 per answer) with a 0.5-mark divergence gate for human escalation. Built a checkpointed bidirectional HubSpot reconciler patching next_payment_date sync bugs.

Technical Decisions

  1. JWT claim extraction in RLS policies

    Replaced per-row database joins with direct JWT claim reads (auth.jwt()), converting sequential table scans into indexed reads.

  2. PostgreSQL advisory locks for gapless invoices

    Applied transactional advisory locks on invoice sequence generation to guarantee contiguous invoice numbers during concurrent checkout sessions.

  3. PayPal issue-name classification over HTTP status

    Replaced generic HTTP 422 retries with issue-name parsing to distinguish terminal account errors from retryable authorization failures.

  4. Claude 3.5 Sonnet batch grading with divergence gates

    Validated Claude 3.5 Sonnet against human-graded exams (matching accuracy within 0.5 raw marks at 1/3 the cost of Opus). Implemented automated blind double-marking with human escalation triggers.

Key Achievements

  • Rewrote 49 RLS policies across 28 tables, cutting admin dashboard query latency from 3.4–4.5s to <1s.
  • Architected PostgreSQL schema with 60 normalized tables and over 200 granular RLS policies.
  • Rebuilt Stripe webhook handlers into 4 endpoints and implemented gapless invoice numbering via PostgreSQL advisory locks.
  • Identified and remediated a PayPal concurrent double-charge bug impacting ~$5.3k in revenue.
  • Built Claude 3.5 Sonnet exam-grading pipeline running at ~$0.01/answer with automated divergence gates.
  • Patched HubSpot synchronization reconciler, fixing ~93 failing PATCH requests per week.

Outcome

The admin dashboard loads in under 1 second, invoice sequences remain contiguous during checkout spikes, PayPal payment failures are classified with exponential backoff retries, and exam answers are graded automatically via LLM batch workers.