Engineering notes

23 notes

Building, AI, architecture, and production.

Real projects, experiments, technical problems, and lessons from production — written so you can see how I think.

A diagnostic order for slow Postgres queries: instrument the database, rank queries by total time, read live wait events, then read the plan
Database performance12 min read

How to Diagnose Slow Postgres Queries in Production

Most teams debug slow Postgres by staring at a query someone complained about. Here's the diagnostic order that finds the real one: what to turn on, what to measure, how to read wait events, and the five shapes slow queries actually come in.

Read
A three second API response broken down by phase, showing eleven milliseconds of database time against event loop blocking and JSON serialisation
Performance engineering12 min read

Why Your Node or Python API Takes 3 Seconds — And It Isn't the Database

Your dashboard takes three seconds and the slow query log is empty. Here's how to find the time: a blocked event loop, a four-megabyte payload, third-party calls inside the request, and two more nobody profiles.

Read
An early-stage SaaS AWS bill broken down by service, with the cuts that took it from roughly four thousand dollars a month to under fifteen hundred
Cloud economics13 min read

Reducing AWS EC2 and RDS Costs for Early-Stage SaaS

A $4,000/month AWS bill at seed stage is usually $1,400 of real workload and $2,600 of idle capacity, forgotten volumes, and NAT gateway charges. Here's the order I work through, with the commands to find each one.

Read
A Vue application calling an LLM through a server proxy, with the API key, prompts and rate limits on the server side and only a composable in the browser
Frontend architecture12 min read

Integrating LLM APIs into Vue.js Applications Cleanly

Most Vue + LLM integrations fail the same four ways: the API key ships in the bundle, provider SDK calls sit inside components, streaming re-renders the tree a hundred times a second, and unvalidated model output lands straight in state. Here's the clean version, with code.

Read
A p95 checkout latency curve staying flat until roughly 180 concurrent checkouts then climbing to 9.6 seconds, beside an EXPLAIN ANALYZE plan whose row estimate is off by five orders of magnitude
Performance engineering11 min read

How to Fix Postgres Checkout Query Latency Under Load

Your checkout is fast until about 180 concurrent shoppers, then it falls off a cliff. Here's how to read the plan, find the lock window, and fix the four causes I actually find — in the order that pays off fastest.

Read
Two heap-over-time traces — a healthy sawtooth returning to baseline after each garbage collection and a leaking staircase that never does — beside the five sources of leaks in Vuex applications
Debugging10 min read

Debugging Memory Leaks in High-Frequency Vuex Applications

“It gets slow after a while, but a refresh fixes it.” That sentence is a complete diagnosis. Here's how to read a heap snapshot properly and the five retention patterns that cause almost every Vuex leak.

Read
A bar chart showing the cost of a single conversation turn growing with every turn because the whole history is resent, beside the cost-per-action formula
AI economics10 min read

A Cost Estimation Model for Production OpenAI API Integrations

Most AI budgets are built by dividing a token price by a guess. Here's the model I use instead — cost per completed action, the quadratic history problem, and the three levers that actually move the bill.

Read
API response time climbing from 180ms on localhost to 2.4 seconds under the first 1,000 users, beside the four hidden risks of an AI-generated MVP
Founder guide9 min read

Just Built Your MVP with AI? Why You Need a Codebase Audit Before Scaling

Cursor, Claude Code and Copilot get a founder to launch in days. They also leave N+1 queries, unbounded polling, IDOR holes and race conditions behind. Here’s what breaks at 1,000 users and how to find it first.

Read
A database at fifteen percent CPU refusing new connections because serverless instances, workers and leaked sessions have consumed all one hundred
Production engineering11 min read

How to Eliminate Database Connection Exhaustion at Scale

Month-end hits and the database starts refusing connections while sitting at 15% CPU. Here's where the connections actually went, how to size the pool properly, and the PgBouncer settings that survive transaction mode.

Read
Two vectors radiating from a shared origin with the angle between them highlighted, next to a similarity score scale
AI fundamentals7 min read

Why Your Next AI Application Doesn’t Need Heavy Math — Just Vectors and Direction

Most founders treat vector search like dark magic and pay for managed infrastructure before understanding how their data is queried. Here’s the whole mechanism, implemented from first principles in about 20 lines of Python.

Read
An endpoint issuing thirty-two thousand database queries averaging four tenths of a millisecond, none of which appear in the slow query log
Production case study10 min read

The N+1 Query Problem in Production: 32,000 Extra Calls in One Endpoint

An invoice list that took 18 seconds for large tenants and 200ms for everyone else. The cause was two lines in a loop and 32,041 individually fast queries — here's how to find yours and stop the next one in CI.

Read
A cost per completed AI action falling from ninety-four cents to eleven through model routing, prompt caching, trimmed conversation history and semantic caching
AI economics12 min read

The Hidden Cost per Call: Architecting LLM Features That Don't Eat Your Margins

An AI feature that costs $0.94 per use has a pricing problem before it has a product problem. Five architectural levers — routing, prompt caching, context hygiene, semantic caching and output limits — measured on the same eval set.

Read
Five AWS line items — an over-provisioned database, NAT gateway processing, unattached disks, idle load balancers and DynamoDB scans — totalling about forty percent of a monthly bill
Cloud economics11 min read

The Silent Cloud Sinks: 5 AWS Resources Burning 40% of Your SaaS Margin

Written for founders reading an AWS bill they did not expect. Five resources that charge for existing rather than working, what each one is in plain English, and the exact commands to find yours this afternoon.

Read
A cost comparison of AWS Lambda and Fargate for the same monthly traffic, showing serverless cheaper for short bursty requests and more expensive for long sustained ones
Cloud economics12 min read

Why Serverless Isn't Always Cheaper: A Real Cost Comparison for Growing SaaS

Same 30M requests a month, opposite answers. Here's the arithmetic behind Lambda versus Fargate, the break-even utilisation, the charges the calculators leave out, and how to model your own workload before migrating anything.

Read
A four hundred and twenty gigabyte Postgres instance broken into live rows, bloat and dead tuples, and indexes that have never been scanned
Database economics12 min read

How to Halve Your PostgreSQL Storage and IOPS Costs in 48 Hours

420GB of database, 162GB of it actually queried. Here's the order that reclaims the rest: find the size, drop unread indexes, repack the bloat, archive cold rows — then resize the disk, not before.

Read
Retrieval results for a question about renewal terms, where the correct document ranks fourteenth and three wrong chunks are returned instead
AI systems13 min read

Why Your RAG Pipeline Hallucinates on Production Data (And How to Fix It)

Your RAG demo was perfect and production is wrong a fifth of the time. Here's why: chunking that cuts clauses in half, vector search that misses exact terms, no re-ranking, and no way for the system to say 'I don't know'.

Read
Abstract architecture diagram showing database indexes, Redis cache, and async job queues optimizing a production app
Architecture6 min read

A Founder Almost Paid $20,000 for a Rewrite. We Fixed It in 10 Days for $3,500.

Before you throw away working software, get a neutral architecture audit. Unindexed queries, sync workloads, and zero caching looked like a $20k rewrite — and weren't.

Read
Legacy monolith connected through a teal AI gateway to LLM services
Architecture & AI9 min read

AI Integration: How to Add LLMs to Legacy Laravel Monoliths (Without Tech Debt)

When clients ask to add AI to 8-year-old Laravel monoliths, the fear is tech debt. Here's how to integrate LLMs with async queues, an AI gateway, and strict JSON contracts — without a rewrite.

Read
A ninety-second agent run broken into steps with per-step retries, an idempotency key on the write, and a human approval gate, instead of one HTTP request that times out
AI architecture12 min read

Building AI Features That Act, Not Just Chat: Reliable Async AI Workers

Your agent works in the notebook and times out in production at thirty seconds. Here's the architecture that survives: accept and return an id, run steps on a queue, make every write idempotent, and put a human gate where it matters.

Read
A rewrite that ships nothing for eighteen months compared with an incremental migration that moves one route at a time behind a proxy and ships from week three
Architecture12 min read

The 'Do Not Rewrite' Playbook: Modernising Legacy Systems Incrementally

Your team wants six months to rebuild it. Here's what actually happens in month seven, and the alternative: find the seam, characterise it, route it, retire it — with production live and revenue flowing the whole way.

Read
Eleven services maintained by five engineers, with the monthly infrastructure and engineering overhead each one carries and the delivery slowdown that follows
Architecture12 min read

The $50,000 Microservices Mistake: When to Monolith Your SaaS Back First

A five-person team maintaining eleven services pays roughly $50,000 a year in overhead before writing a feature — and most of it is not server cost. Here's the arithmetic, the symptoms of a premature split, and how to merge back safely.

Read
Seven areas a technical due diligence review examines before a funding round, from secrets in the repository to untested backups and rising cost per customer
Founder guide13 min read

How to Run an In-House Architecture Audit Before Your Next Funding Round

A checklist for founders running their own technical due diligence before investors or an acquirer run theirs. Seven areas, what each finding does to price or timeline, and the one-page output to hand over.

Read

Need a developer for your project?

I build websites, portals, and AI tools for businesses.

See services & pricing