Katkat

Design Composable Event Recommendations

StubHubSoftware Engineer · Onsite

Last updated

This problem tests your ability to design a flexible, object-oriented recommendation engine that allows for composable filtering and ranking logic using the strategy or decorator pattern.

Problem Statement

You are building a recommendation engine for a ticket marketplace. Users have specific preferences, and events must be filtered and ranked based on these rules. You need to implement a system that evaluates an Event against a collection of Filter and Ranker strategies.

An Event is represented as follows:

class Event:
    def __init__(self, id, category, price, popularity_score, start_time):
        self.id = id
        self.category = category
        self.price = price
        self.popularity_score = popularity_score
        self.start_time = start_time

Tasks:

  1. Define an interface or abstract base class for Filter (e.g., CategoryFilter, PriceRangeFilter).
  2. Define an interface for Ranker (e.g., PopularityRanker, PriceRanker).
  3. Implement a RecommendationEngine class that takes a list of Event objects, applies all filters, and then sorts the remaining events based on a weighted combination of active rankers.

Example:

Input: A list of 3 events. Filter: CategoryFilter('Sports'). Ranker: PopularityRanker.

  • Event A: {'id': 1, 'category': 'Sports', 'price': 50, 'popularity_score': 0.8}
  • Event B: {'id': 2, 'category': 'Music', 'price': 30, 'popularity_score': 0.9}
  • Event C: {'id': 3, 'category': 'Sports', 'price': 100, 'popularity_score': 0.7}

Output: [Event A, Event C] (filtered by 'Sports' and sorted by popularity).

Constraints:

  • Use clean, extensible code (follow the Open/Closed Principle).
  • Handle the case where no events match the filters.
  • Ensure the ranking logic can handle multiple rankers simultaneously (e.g., a weighted score of popularity and price).

Hints

Hint 1

Consider using the Strategy Pattern to encapsulate the filtering and ranking algorithms as interchangeable objects.

Hint 2

For the ranking system, define a common scoring method that returns a float, allowing you to sum weighted results from multiple rankers.

Hint 3

Maintain a pipeline architecture where the engine processes a list of filters sequentially before passing the result to the ranker ensemble.

Follow-up questions

  • How would you optimize the system if the number of events grew to millions and filtering had to happen in sub-100ms?
  • How would you introduce 'diversity' into the top 10 recommendations to ensure the user doesn't just see the same category?
  • If rankers have different scales (e.g., price is 0-500, popularity is 0-1), how would you normalize the scores before weighting them?