How would you scale rule evaluation?
RipplingSoftware Engineer · Technical ScreenLast updated
This question tests your ability to design a high-throughput, rule-based processing engine that balances performance, scalability, and maintainability under high load.
Problem Statement
Design an expense-policy rule engine that determines whether an expense report should be auto-approved, flagged for review, or rejected based on a set of dynamic rules.
Functional Requirements
- Rule Definition: Rules consist of conditions (e.g.,
amount > 500,category == 'Travel',employee_tenure < 6 months). - Batch Processing: Support processing batches of up to 1,000 expense records against one million potential active rules.
- Dynamic Updates: Rules must be versioned and updatable without taking the system offline.
Non-Functional Requirements
- Scale: Handle high request volume with low latency (sub-200ms per batch).
- Isolation: Ensure rules for different companies (tenants) are isolated and performant.
- Observability: Track which rule triggered a specific decision for auditing purposes.
Your Task
Provide a high-level design that covers:
- Data Model: How to store and represent the million rules efficiently.
- Evaluation Strategy: How to filter the million rules down to the ones relevant to a specific expense without iterating through all of them.
- API Design: Define the interface for submitting an expense batch and retrieving audit logs.
- Scalability: Describe how you would handle tenant-specific bursts and system updates.
Hints
Hint 1
Consider using an inverted index (e.g., a predicate tree or trie) to map expense attributes to relevant rule subsets.
Hint 2
Think about whether the rules can be pre-compiled into a query language or an executable format (like bitsets or bytecode) to accelerate evaluation.
Hint 3
Discuss using a cache layer for frequently accessed rules and a pub-sub mechanism to invalidate caches during rule updates.
Follow-up questions
- How would you handle a scenario where rules overlap or conflict (e.g., two rules give contradictory outcomes for the same expense)?
- If the rule evaluation requires an external database lookup (e.g., checking employee payroll history), how would you optimize this to avoid excessive latency?
- How would you implement a 'dry run' feature that allows users to test new rules against historical data before they go live?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.