Functional Requirements:
The system must recommend the most relevant 5 to 10 keywords in response to a user's search input.
Non-Functional Requirements:
Based on the assumption of processing 3.5 billion queries akin to Google's volume, with 2 billion of these being unique and requiring storage. Given that the average query length is 15 characters, and each character occupies 2 bytes, the calculation for daily storage needs is as follows: 2 billion queries multiplied by 15 characters, further multiplied by 2 bytes, equals 60 billion bytes or 60GB for all daily queries. Therefore, the annual storage requirement is calculated as 60GB per day multiplied by 365 days, totaling 21.9 terabytes per year.
Incoming Bandwidth:
The daily influx consists of 3.5 billion queries, each query averaging 15 characters at 2 bytes per character, summing up to 105 billion bytes or 105GB per day. Breaking this down further into seconds gives us a rate of approximately 1.2GB per second, or equivalently, 10 gigabits per second (10Gb/s).
Outgoing Bandwidth:
Considering the system provides 5 to 10 suggestions per query, the maximum outgoing bandwidth could reach up to 10 times 1.2GB per second, which equates to 12GB/s.
GET /suggestions/{prefix}
This endpoint retrieves suggestions for queries that begin with the specified "prefix." It returns a JSON object with an array of suggestions, each containing an "id" and the "suggestion" itself. For example:
[
{"id": 1, "suggestion": "Apple"},
{"id": 2, "suggestion": "Apricot"}
]
POST /add/{query}
This endpoint is used to insert a "query" into the database if it qualifies as trending, meaning it has reached a specific popularity threshold through repeated searches.
Addressing these challenges involves implementing strategies to maintain system performance and reliability:
Mitigating Database Overload
Resolving Cache Invalidation Issues
Overcoming Performance Bottlenecks
These strategies aim to ensure the system remains responsive, scalable, and capable of handling the dynamic nature of user queries and trending analysis without compromising on performance or user experience.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?