Skip to content

High-level Design of the Typeahead Suggestion System

According to our requirements, the system shouldn’t just suggest queries in real time with minimum latency but should also store the new search queries in the database. This way, the user gets suggestions based on popular and recent searches.

Our proposed system should do the following:

  • Provide suggestions based on the search history of the user.

  • Store all the new and trending queries in the database to include them in the list of suggestions.

When a user starts typing a query, every typed character hits one of the application servers. Let’s assume that we have a suggestions service that obtains the top ten suggestions from the cache, Redis, and returns them as a response to the client. In addition to this, suppose we have another service known as an assembler. An assembler collects the user searches, applies some analytics to rank the searches, and stores them in a NoSQL database that’s distributed across several nodes.

Furthermore, we also need load balancers to distribute the incoming requests evenly. We also add application servers as entry points for clients so that they can forward requests to the appropriate microservices. These web servers encapsulate the internal system architecture and provide other services, such as authentication, monitoring, request shaping, management, and more.

Since the system provides suggestions to the user and adds trending queries to the databases, we need the following APIs.

This API call retrieves suggestions from the servers. This call is made via the suggestion service and returns the response to the client.

The following table explains the parameter that’s passed to the API call: “

ParameterDescription
prefixThis refers to whatever the user has typed in the search bar.

This API call adds a trending query to the database via an assembler if the query has already been searched and has crossed a certain threshold. “

ParameterDescription
queryThis represents a frequently searched query that crosses the predefined limit.

In the next lesson, we’ll learn about an efficient data structure that’s used to store the suggestions or prefixes.

Requirements of the Typeahead Suggestion System’s DesignData Structure for Storing Prefixes