What is a fast and efficient way to implement the server-side component for an autocomplete feature in an html input box?
I am writing a service to autocomplete use
I had a similar requirement.
I used relational database with a single well-indexed synthetic table (avoiding joins and views to speed up lookups), and in-memory cache (Ehcache) to store most used entries.
By using MRU cache you'll be able to have instant response times for most of the lookups, and there is probably nothing that can beat relational database in accessing indexed column in a big table stored on disk.
This is solution for big datasets you can't store on the client and it works pretty fast (non-cached lookup was always retrieved under 0.5 seconds in my case). It's also horizontally scalable - you can always add additional servers and database servers.
You could also play with caching of only the most used results on the client, especially if you've already implemented it. In my case, server-side solution is fast enough, and client load times are slow enough as it is, so it's not warranted.
P.S. Having client query only when user pauses for a certain amount of time to avoid repeated lookups as suggested is a good solution. On my client, I query database only after first three characters are entered, since less than that returns too many results in all instances.