HP

Blog · · 2 min read

Moving AI scoring to the server: quotas, rate limits and burst protection

Calling an AI API straight from the browser makes latency unpredictable and billing uncontrolled. How I moved scoring to server endpoints with limits.

SecuritySoftware engineering

FrancoBuddy helps people practise for the TEF Canada French exam. Students speak or write an answer and the app scores it with an AI model. The first version made those AI calls from the client side. That caused two problems.

The two problems

  1. Unpredictable speed. Every user's browser called the external API directly, so response time depended on things I could not see or control.
  2. Uncontrolled cost. If the AI API is called from client-side code, anyone can call it as often as they like. The bill belongs to the owner of the key, not the user.

The change

I moved the scoring logic to dedicated server endpoints. The browser now sends the answer to my server, and only the server talks to the AI service. The server also decides whether a request is allowed. I added three controls:

  • A per-student daily quota. Each student gets a fixed number of scored attempts a day.
  • Rate limiting. Requests from the same user arriving too fast are refused.
  • Burst protection. A short, sudden spike of calls is stopped even if the daily quota is not used up.

Why three and not one

They protect against different things. The quota stops slow, steady overuse. The rate limit stops a script hammering the API. The burst protection stops a short spike that stays under the other two. Together they put a ceiling on the worst case cost.

The same idea in the database

The app uses Firebase Authentication and Cloud Firestore. I enforced strict Firestore security rules, so the database itself refuses requests a user should not be able to make. Rules in the database matter because the browser is not a place you can trust: anything that runs there can be changed by the person using it.

Limits of what I did

This is about engineering controls, not scale. I do not claim user counts, traffic or revenue for the product. The measurable results from the project are in tests and type safety: 136 passing tests and 0 type errors.

If you build anything that calls a paid API, put it behind a server first and decide the limits before you launch. The project and its evidence are on my portfolio.