The challenge
I designed and built a new AI product end to end, from the first architecture sketch to go-live preparation. Users upload images and get a structured AI analysis back.
Three things had to hold from day one:
- The app must never wait on the model. AI calls are slow and cost money, so they can’t sit inside a web request.
- AI output must be dependable. The results are stored and rendered, so free-form text wasn’t good enough.
- Every paid job is charged exactly once, even when functions retry or payment webhooks arrive twice.
The approach
- Safe, direct uploads to S3. The browser uploads files straight to S3 with a pre-signed request. File type and size limits are enforced by the storage policy itself, so clients can’t widen them and upload traffic never touches the application servers.
- Event-driven and parallel by design. Each upload is its own event. A first serverless step normalizes the image to a fixed size and a modern format, which keeps storage and model-input costs predictable, and a second step calls a multimodal model. Every job runs in its own function invocation, so jobs process in parallel with no worker pool to size.
- Async waiting without a single-page app. The frontend is server-rendered with HTMX. A pending result polls a lightweight status endpoint and swaps itself for the finished result. There’s no frontend build and no client state to keep in sync.
- Reliable AI output in layers. The model’s native structured-output mode enforces a schema generated from the domain types while the answer is being generated. Every response is still validated into a typed result, because a valid shape doesn’t guarantee valid content. If validation fails, the model gets one repair attempt with the error fed back; anything still invalid is rejected, never shown, and its credit refunded. Validation failures are tracked as a metric, so a model update that quietly gets worse shows up immediately.
- Credits that never double-charge. Each job reserves a credit before the model runs and settles it afterwards: committed on success, refunded on failure. The balance and an append-only ledger change together in one transaction with idempotency keys, so retries and replayed payment webhooks can’t charge twice, even under concurrent load.
- Clean architecture. Business logic depends only on interfaces. The model provider, storage, authentication and payments are adapters. Each model adapter maps the same domain schema to its provider’s structured-output format, so switching AI providers means writing one adapter, not touching the business rules.
Key decisions and trade-offs
Asynchronous over request/response. Polling and status tracking add moving parts, but the app stays responsive and every job scales independently.
Status in the database, results in object storage. Database rows stay small and cheap, and large results live where storage costs least.
Reserve at the front door, settle at the end. The credit is reserved when an upload is authorized, before any file exists, so unpaid work can never start. It’s settled only after a valid result, so users never pay for a failure, and the ledger explains every balance change.
Results
- From idea to launch-ready, solo, in about six months.
- A structured go-live readiness audit across security, compliance and operations before launch.
- Built with an AI-assisted engineering workflow, the same approach I help teams adopt.
What I’d take into the next AI product
- Observe the money path from day one. Payments are where silent failures cost the most, so they need alerts before anything else.
- Treat models and prompts like code. A fixed evaluation set makes switching to a new model version a measured decision, not a guess.
- Start simple on real-time. Polling is enough at launch; push-based updates can come once usage justifies them.