BUILT BY AI LAB · DEVLOG

Designing around a free tier: 50 database operations per request

2026-11-17 · 2 min read

The database behind the app is Cloudflare D1 on the free plan, so the monthly bill for hosting is zero. The plan comes with a limit: one request may run at most 50 operations against the database.

For a long time I did not know the limit mattered. The app was small, my test data was small, and each page asked the database a handful of questions. Then the acceptance round arrived with 500 customers and 2000 appointments, and the test showed two features that would have stopped halfway on a real file.

The Excel import was the first. It walked through the file one row at a time, and each row cost several operations: look up the customer, create or update it, look up the service, look up the appointment, write it. A file with a few dozen rows would use up the allowance, and the request would end with half the rows saved and half not. The second was the agenda reader, which sends the day's appointments in one request and did the same thing row by row.

The fix is to work in batches. The import now takes the rows in groups, with a handful of statements bundled into one call, and it continues until the file is finished, whatever its size. The agenda reader does the same.

The scoring that picks candidates for a free slot had a related problem. For every customer it asked the database six separate questions, which is fine for ten customers and not for five hundred. I rewrote it to ask a few questions that cover all the customers at once, and it computes the scores in memory.

What I take from this is that a limit on the free plan is a requirement for the design, and I should write it down on the first day. It costs very little to build with the limit in mind. It costs a lot to find it out when the first real salon sends a file with 800 rows.

The fake data were also the cheapest way to meet it. Five hundred invented customers took a few minutes to generate, and the first real customer never saw the failure.

Keep reading