Provide suggestions to users (maybe top 10)
Low latency
Reliability
Scalability
Availability
1 billion Daily Users and each user hits 10 queries per day on an avg
10 billion queries/day
(10 billion / 24*60*60) QPS
get_suggestions(String query)
Use tries
For database, we can use multiple databases for different use cases. For storing user metadata, use MySQL. And for query and suggestions, use NoSQL. Use Cassandra to store unstructured data in tabular format. Use HDFS for storing huge amount of data. Use Redis cache for frequently used suggestions. And use data replication to keep our data reliable and durable. Do data sharding to avoid overloading a server.
Clients start typing in the browser search bar. The request goes to load balancer, and load balancer calls the application server. Application server makes an API call to the suggestion service which fetches top 10 suggestions from the Redis cache.
Suggestion flow :
Clients start typing in the browser search bar. The request goes to load balancer, and load balancer calls the application server. Application server makes an API call to the suggestion service which fetches top 10 suggestions from the Redis cache.
Adding new suggesions :
When client types queries for which are new and the database does not have suggestions for it, this request goes to the Load balancer then to the application server and then it goes to the assembler. In this, the collection service just dumps all the unstructured massive data in Hadoop. Then this data is fetched by aggregator service which consolidates and aggregates this data and stores it into Cassandra DB which stores unstructured data into tabular format. Then this data in Cassandra is fetched by the trie builder which stores all this data in trie data structure and stores it finally in our NoSQL database where all the suggestions are persisted. And most popular queries are stored in Redis cache. From Redis cache and NoSQL DB, the suggestion service fetches the suggestions and send it to the user.
Databases will internally use a trie data structure to store and retrieve suggestions. Suggestion service fetches suggestions from DB and redis cache and sends to the user. Assember consists of Collector, Aggregator, Hadoop, Cassandra, Trie Builder components.
Assembler does not build the trie synchronously because this is huge data and trie data structure can be huge, updating this data in real time will slow down the system so it is done asynchronously.
Try to discuss as many failure scenarios/bottlenecks as possible.
Use of Multiple servers for critical components will make our system fault tolerant.