Course Content
Data Structures & Algorithms
Full Stack Web Development
Understanding and playing with DOM (Document Object Model)
0/2
MERN project
0/2
Low Level System Design
LLD Topics
High Level System Design
Fast-Track to Full Spectrum Software Engineering
1. Get Suggestions API

API Endpoint:

GET /api/suggestions

 

Description:

This is the primary API endpoint that handles user input and returns a list of suggestions based on the query typed by the user. It performs the search for matching or relevant items in the database or search index and returns the suggestions in real-time.

 

Request Parameters:

  • query (string, required): The partial search term that the user is typing (e.g., “New Y” when the user types it in the search bar).
  • limit (integer, optional, default: 10): The maximum number of suggestions to return. This is useful for limiting the size of the result set.
  • user_id (string, optional): A unique user identifier to provide personalized suggestions based on the user’s previous search history or preferences.

 

Response:

 

  • suggestions (array of strings): A list of suggestion strings that match the typed query, e.g., ["New York", "New Year", "New Zealand"].
  • status (string): A status message indicating whether the request was successful (e.g., OK).
  • error (string, optional): Any error messages or descriptions in case the query failed.

 

Example Request:
GET /api/suggestions?query=New%20Y&limit=5

 

Example Response:
{
"status": "OK",
"suggestions": [
"New York",
"New Year",
"New Zealand",
"New York Times",
"New York City"
]
}


2. Get Popular Queries API

API Endpoint:

GET /api/popular-queries

 

Description:

This API is used to fetch a list of popular search queries that users are frequently searching for. These popular queries can be used as suggestions to show the user trending or frequently searched terms, which could be pre-defined or dynamically fetched.

 

Request Parameters:

  • limit (integer, optional, default: 10): The maximum number of popular queries to return.

 

Response:

  • popular_queries (array of strings): A list of popular search queries, such as ["New York", "weather", "restaurants near me"].
  • status (string): A status message indicating whether the request was successful.

 

Example Request:
GET /api/popular-queries?limit=5

 

Example Response:
{
"status": "OK",
"popular_queries": [
"New York",
"weather",
"restaurants near me",
"restaurants in NYC",
"New Year events"
]
}


3. Get Personalized Suggestions API

API Endpoint:

GET /api/personalized-suggestions

 

Description:

This API is used to return personalized suggestions based on the user’s search history, preferences, and interactions. By providing a user_id or session_token, the system can fetch suggestions that are tailored to the individual user.

 

Request Parameters:

  • query (string, required): The partial search query typed by the user.
  • user_id (string, required): A unique identifier for the user to fetch personalized suggestions.
  • limit (integer, optional, default: 10): The maximum number of personalized suggestions to return.

 

Response:

  • personalized_suggestions (array of strings): A list of suggestions based on the user’s search history or preferences.
  • status (string): A status message indicating whether the request was successful.

 

Example Request:
GET /api/personalized-suggestions?query=New%20Y&user_id=12345&limit=5

 

Example Response:
{
"status": "OK",
"personalized_suggestions": [
"New York City",
"New Year's Eve events",
"New York Times",
"New York restaurants",
"New York weather"
]
}


4. Save Search History API

API Endpoint:

POST /api/save-search-history

 

Description:

This API saves the user’s search history to enable better personalization of future suggestions. It tracks the terms a user has searched for, which can be used for improving typeahead suggestions and personalization.

 

Request Body:

  • user_id (string, required): A unique identifier for the user.
  • query (string, required): The query that the user just searched for.
  • timestamp (string, optional): The timestamp when the query was made.

 

Response:

  • status (string): A status message indicating whether the search history was successfully saved.

 

Example Request:
POST /api/save-search-history
{
"user_id": "12345",
"query": "New York restaurants",
"timestamp": "2025-03-31T14:30:00Z"
}

 

Example Response:
{
"status": "OK"
}


5. Clear Search History API

API Endpoint:

POST /api/clear-search-history

 

Description:

This API is used to clear the user’s search history. This could be useful for scenarios where a user wants to delete their search history for privacy reasons or for the system to forget old queries.

 

Request Body:

  • user_id (string, required): A unique identifier for the user.

 

Response:

 

  • status (string): A status message indicating whether the search history was successfully cleared.

 

Example Request:
POST /api/clear-search-history
{
"user_id": "12345"
}

 

Example Response:
{
"status": "OK"
}


6. Health Check API (for System Monitoring)

API Endpoint:

GET /api/health

 

Description:

This API is useful for monitoring the health of the Typeahead Suggestion system, ensuring that all components (e.g., database, cache, search index) are operational.

 

Response:

  • status (string): A status message indicating the health of the system (e.g., OK, ERROR).
  • components (object): Status for different components (e.g., database, cache, etc.), showing whether they are operational.

 

Example Request:
GET /api/health

 

Example Response:
{
"status": "OK",
"components": {
"database": "healthy",
"cache": "healthy",
"search_index": "healthy"
}
}


7. Bulk Suggestions API (Optional)

API Endpoint:

POST /api/bulk-suggestions

 

Description:

This API handles multiple suggestions requests in bulk, allowing the system to process many queries at once. This is useful for optimizing the performance of the system when multiple suggestions are needed at the same time, for instance, during batch processing or bulk analytics.

 

Request Body:

  • queries (array of strings, required): A list of partial search queries for which suggestions are needed.

 

Response:

  • status (string): A status message indicating whether the request was successful.
  • results (array of arrays of strings): A list of arrays, where each array contains the suggestions for the corresponding query.

 

Example Request:
POST /api/bulk-suggestions
{
"queries": ["New Y", "Restaur", "Weather"]
}

 

Example Response:
{
"status": "OK",
"results": [
["New York", "New Year", "New Zealand"],
["Restaurant", "Restaurants near me", "Restaurant reviews"],
["Weather", "Weather forecast", "Weather near me"]
]
}
0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.