A search autocomplete that works in staging but melts production

  • A community for building, creating, and growing with AI.

    Welcome to AI Forums, a community for people using AI to build products, automate workflows, create content, and grow businesses. Discuss vibe coding, AI agents, Claude Code, Codex, automation, AI tools, product launches, marketing, and the latest developments in AI.

    Join the Community (it's FREE)!

digitalTinkerer

Starter account
Messages
3
Here's a failure mode worth discussing: an AI-generated autocomplete feature looks perfect during testing, but it queries the database on every keystroke. Under heavy traffic, that can turn a harmless search box into thousands of unnecessary requests.

The feature technically works, yet it misses debouncing, caching, request limits, and realistic load tests. How do you make sure agents consider non-functional requirements instead of only the visible feature?
 
I'd specify observable performance requirements, not just 'make autocomplete fast.' For instance: debounce typing, cancel obsolete requests, cap result size, index the search fields, and measure p95 latency under a load profile that resembles the real app. None of that guarantees the feature will hold forever, but it gives the agent something concrete to implement and gives reviewers something concrete to verify. A passing unit test doesn't tell you how many queries hit your database per second.
 
The other half of this problem is that a debounce only reduces keystrokes, it does nothing about requests already in flight.

Abort stale requests. If every keystroke fires a request, responses can arrive out of order and the field briefly shows results for a prefix the user already typed past. An AbortController keyed to the latest query fixes both the correctness bug and the pile of live connections.

Cap the work per query, not just per user. Prefix search on a large table is only cheap if the index covers the prefix. ORDER BY relevance over an unindexed LIKE '%term%' does a full scan per keystroke no matter how well the front end behaves. Prefix match plus LIMIT plus a covering index is usually the difference between 2ms and 400ms at p95.

On the agent question: non-functional requirements get implemented when they are written as measurable acceptance criteria in the task, not as intentions. "Autocomplete should be fast" is unverifiable, so it gets skipped. "Under 20 concurrent typers, p95 under 150ms, fewer than 3 DB queries per session-second" is something an agent can implement against and a reviewer can reject on. The failure mode is usually not that agents ignore performance, it is that performance was never made checkable in the first place.
 
This is my favorite example of why a feature can be visually correct and operationally dangerous. You can type into the box, see suggestions, and mark the story done. But there's a second product hiding behind the screen: request volume, indexes, rate limits, cache behavior, and what happens when a slower response arrives after a newer one.

The review question should be, 'What happens if ten thousand people do this at once?' You don't have to personally write the implementation to ask that question, but somebody needs to own the answer. If the agent doesn't test those assumptions, its confidence is irrelevant. I'd rather have a boring search box that stays up than a clever one that takes the site down during a sale.
 
Back
Top