Design an Extensible Expense Rule Engine
Company: Rippling
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
# Design an Extensible Expense Rule Engine
You receive expenses with fields such as `expense_id`, `item_id`, `expense_type`, `amount_in_usd`, `seller_type`, and `seller_name`. Design and implement the core of `evaluate_rules(rules, expenses)`, which evaluates every configured rule against every expense and returns every violation.
The initial rules are:
- Any expense above 175 violates the total-expense limit.
- An expense from a restaurant seller above 45 violates the restaurant limit.
- Any expense whose type is entertainment violates the prohibited-type rule.
For example:
```text
Expense: {expense_id: "1", expense_type: "Food", amount_in_usd: 250, seller_type: "restaurant"}
Violations:
- Total expense should not be greater than 175
- Restaurant expense should not be greater than 45
```
New rule types should be addable without modifying the central evaluation loop. Explain your interfaces, result model, ordering, error policy, testing strategy, and complexity.
### Clarifying Questions to Ask
- Are monetary values represented as integer cents or exact decimals?
- Should malformed expenses stop the batch or produce a validation violation?
- Must violations preserve expense order and rule-configuration order?
- Can rules depend only on one expense, or will aggregate rules be added later?
### What a Strong Answer Covers
- A rule abstraction with stable identity, description, and one evaluation method.
- Separate implementations for unconditional limits, conditional limits, and prohibited types.
- A result object that identifies both the expense and violated rule.
- Deterministic evaluation order and an explicit malformed-input policy.
- Extension through registration or dependency injection instead of new engine branches.
- Focused rule tests plus composition tests proving all applicable rules run.
### Follow-up Questions
- How would you add a daily aggregate limit that depends on multiple expenses?
- How would rule versions be audited when policy changes?
- When would a data-driven rule specification be preferable to one class per rule?
Overview: Design an extensible expense rule engine that reports every applicable violation for each expense. The answer separates rule implementations from the evaluation loop, defines deterministic structured results and money handling, and covers boundary tests, malformed data, rule versioning, aggregate-rule extensions, and OOP trade-offs.
Read the full Rippling Software Engineer interview experience this question came from