Menu

1 / 2

Make the database do the minimum: six rules I give my AI

DEV Community: postgres·Matteo Mazzocchi·6 days ago
#xGBRR6Uh
#devtopostgresql#devto#dev#every#await
Reading 0:00
15s threshold

I build CRMs and back-office systems for small Italian companies, and I write most of the code with an AI assistant. That works well for a lot of things. It works badly for one thing in particular: the database.

My AI writes queries that are correct. They return the right rows, the tests pass, the page loads. With a hundred rows in the table. After a year of real use, the same page can take seconds, and the database plan you're paying for is suddenly too small.

The reason is simple. In my setups the database is the small, expensive resource, and the application server is the big, cheap one. Every query, every megabyte of database memory, has to justify itself. The AI doesn't know that. It writes the shortest code that works, and the shortest code usually asks the database to do more than it should.

One system I worked on had a sync loop that re-read calendars every minute "to see if anything changed". Nobody noticed it in development.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.