Skip to content
All case studies

AI tutoring startup

An AI tutoring and exam-preparation platform used by millions of pupils and students across web, iOS and Android. Inside its existing codebase, I replaced message-count usage limits with cost-based metering and built the tutor's memory pipeline.

Role
Senior Software Engineer
Period
2026
Students
Millions
Metered requests
Millions a month

The problem

The platform is an AI tutor for exam preparation, used by millions of pupils and students across web, iOS and Android. It limited usage by counting messages, but the company pays per token, and a message isn't a unit of cost. A long conversation over a big context and a one-line question counted exactly the same, and cost very different amounts. At millions of requests a month, that difference showed up directly in what the company paid.

The tutor also had to remember students between sessions. That meant pulling lasting facts out of conversations, without adding work to the request a student is waiting on, and without turning the database into a nightly bottleneck.

My role

I joined as a senior engineer in an existing codebase, working directly with the CTO and the product team in agile sprints. Usage metering, credit top-ups, the usage admin and the memory pipeline were mine. The architecture and conventions were already there, so the job was to change two load-bearing parts of a live product, without proposing a rewrite.

Key decisions

Charging cost instead of messages

Extending the message counter would have kept measuring something the business doesn't pay for, so I built a second usage system that charges what a request actually costs, and moved every plan tier onto it. Allowances and top-ups are separate credit buckets, each with its own expiry, and spend is deducted across them in order. The nice part is that adding a new chargeable feature became a matter of declaring its budget, instead of editing gating logic in several places.

Every tutor request
  1. Hold Before the model call The affordability check reserves credit for the request, with a per-feature expiry.
  2. Model call The expensive part The tutor answers. If the call fails, nothing is charged.
  3. Charge Only on success The hold resolves into a usage record across the student's credit buckets, in order.

A failed request costs the student nothing, and because holds expire per feature, an abandoned request can't strand anyone's credit.

Logging before enforcing

Switching enforcement on in one go would have meant trusting brand-new numbers with people's access. So usage was logged first, without blocking anyone, with the usage bars opt-in, and the figures could be checked against real traffic before they were allowed to deny anyone service. I also wrote several dozen tests so an external QA team could take the feature over, covering every usage path and the switchover itself.

Prices per country, with Stripe as the source

Credit top-ups sit next to the subscriptions, priced for what students in each country can actually afford, rather than one price per currency. The price catalogue is pushed to Stripe per country and currency, with Stripe as the source of truth. Bank transfers settle days after checkout, so a purchase stays pending until the credit really lands, instead of being assumed on redirect.

Memory off the request path

Memory runs as a background pipeline on Inngest. An LLM pass extracts lasting facts from conversations, and a nightly pass merges and prunes whatever piles up. The work fans out per user with a concurrency cap, and the nightly runs are spread across a four-hour window, so the database load stays flat overnight instead of arriving as one big spike.

Result

Every plan tier runs on cost-based usage now, so the limit the product enforces and the amount the company pays for are the same number. The admin side breaks consumption down by user type, so the cost of serving each tier is something you can see, rather than guess.

See the request and memory flows.

Technology

  • TypeScript
  • Next.js
  • tRPC
  • PostgreSQL
  • Drizzle ORM
  • Inngest
  • Stripe
  • Bun