KatInterview

Pluggable Filter and Scoring Pipeline for Ticket Listings

Data Structure DesignModel answer
MediumModel answerData Structure Designobject-oriented-designstrategy-patternopen-closed-principle

Last updated

Design an extensible object-oriented engine that drops ineligible events with pluggable rules, then orders the rest by a weighted blend of scoring strategies.

Ticket Listings: Pluggable Filtering and Scoring

A ticket marketplace wants to suggest events to users based on their preferences. Eligibility rules and ordering rules will keep growing over time, so the design must make it easy to add new ones without editing existing code.

Each event is described by this class:

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

What to build

  1. An abstraction for filters, which decide whether an event is eligible. Provide concrete examples such as a category filter and a price-range filter.
  2. An abstraction for rankers, which assign an event a score used for ordering. Provide concrete examples such as a popularity ranker and a price ranker.
  3. A RecommendationEngine that accepts a list of events, removes any event rejected by a filter, and orders the survivors by a weighted combination of all active rankers.

Example

Filter: category is 'Sports'. Ranker: popularity.

idcategorypricepopularity_score
1Sports500.8
2Music300.9
3Sports1000.7

Expected result: events 1 and 3, in that order (event 2 is dropped by the filter; the remaining two are ordered by popularity).

Requirements

  • The code should be clean and extensible and follow the Open/Closed Principle: adding a new filter or ranker must not require changing the engine.
  • If no events pass the filters, the engine must return an empty result without error.
  • Several rankers must be usable at once, for example a weighted blend of popularity and price.

What to discuss

Explain your class structure, how filters are combined, how scores from rankers with different scales are blended, the complexity of the pipeline, and the edge cases you handle.

Hints

Hint 1

Treat the work as two stages: first a boolean eligibility check per event (all filters must agree), then a numeric ordering of whatever survived.

Hint 2

Give every ranker the same contract, 'a higher score is better', so a cheaper-is-better ranker can simply return the negated price and the engine never needs to know directions.

Hint 3

Price might range up to hundreds while popularity sits between 0 and 1. Rescale each ranker's scores across the surviving candidates before applying weights, and decide what to do when every candidate has the same raw score.

Hint 4

Think about the boundaries: an empty candidate list, no rankers configured, one single candidate, negative weights, and an invalid price range.