Take the 2-minute tour ×

When handling autocompletion feature for a form field where every character typed by a user triggers an api call for suggestions, how do you proxy this call to scale?

  • Direct from java script is not possible due to cross domain restrictions, and not secure because that would expose the api keys.
  • Moving this to the controller or model, would incur a lot of queries to the server side that would put heavy burden on them when the active user base has reached a certain limit.

Whats the standard industry practice for such a feature?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Not sure what you mean by "proxy this call", but in general:

  1. You can use JSONP for cross domain queries. But you pay performance penalty on a client side.

  2. It's OK to query same domain. There is no single answer since topic is very generic. How you scale depends on your infrastructure. If application is designed to scale horizontally you scale just by adding more servers to your servers pool. Which is pretty simple using Amazon or Azure cloud services. It is also important to optimize database queries and indexes so that database responds fast. If user base is big you can even have multiple copies of the same databases to help with performance.

Don't worry about optimizations prematurely since you may never get to that point. If you get it is good problem to have and in this case solution is trivial.

share|improve this answer
By proxy i meant, javascript sending a query to controller, and then controller dispatching an API call to a 3rd party service. We will investigate the Jsonp soluton first. Thank You. –  tven Jan 11 '13 at 18:26

You'll need to be very smart on the client and on the server. Use a lot of caching everywhere to avoid extra work. Use CORS or JSONP. And frankly speaking this is a lot of work. Not speaking of Lucene/SOLR being not very autocomplete capable engine. Btw: look at www.rockitsearch.com . It has implementation autocomple with all the basic features. All you'll need to do is: register and export your data there. And then integrate your widget on your website.

share|improve this answer

Your Answer


