Sprout Mobile Autocomplete

Today we decided that we needed to have autocompletion of usernames in the compose view for the mobile apps.  There are a lot of ways we could do it, and trust me we talked through a lot of them.  Our solution though, I think is awesome.  I’ll let you in on a little secret: it’s not complicated.  And in that lies the beauty.

We talked about setting up an endpoint to our API to poll for usernames on a user’s social graph in real time, but this would be expensive to develop the back-end, and slow to to the user.  At Sprout Social we’re all about the user experience so that proved not to be our best option.

We did some thinking and, hat tip to Aaron for coming up with this, found an awesome solution.  The people you are most likely to be talking with are people that appear in your inbox and in your Twitter stream.  So, every time we see a Twitter screenname in your stream or inbox, we add them to a list.  Then when someone hits that ‘@’ symbol in compose we poll that local list for people matching the first few characters.  Then every time you select a user using autocomplete we increment their count.  We use that count value to break ties between queries that are equal.

As a fallback, if you have no matches locally, we will hit the API to look for users.  We made this API call cheaper by searching the full Twitter namespace, instead of having tailor results for each user based on their followers and following lists.  The selected user is then added locally so this API call doesn’t need to be repeated in the future.

We were skeptical about how useful this would be immediately, but after about 5 hours of using it, the local cache has everyone I want to reply to.  And as a bonus, the people I’ve responded to most are the people that show up at the top of the list.

Simplicity is beautiful.

— @andylavoy