Design expense rules engine and return type
Design a Rules Engine for Corporate Card Expenses
Context
You are tasked with building an expense policy engine for a corporate credit-card system. In this system, managers define policies (referred to as rules) that must be evaluated against individual expense transactions. Each expense transaction is represented as a dictionary or map, where both keys and values are strings.
Task
Your design and description should cover the implementation of the following:
- Rule Representation: Define a structure for rules that can support at least the four sample policies provided below and is scalable to hundreds of rules.
- Evaluation Function: Design a function with the signature
evaluateRules(rules: list <rule>, expenses: list <expense>) -> ?. - API Response: Clearly define the return type of the
evaluateRulesfunction as an API response suitable for consumption by downstream services and user interfaces. - Key Considerations: Explain your approach to:
- Conflict handling and rule precedence.
- Auditing and providing explanations for rule violations.
- Performance and scalability of the system.
- How managers select, create, and manage rules within the system.
- Assumptions & Clarifications: State any assumptions you make and product clarifications you would seek before proceeding with implementation.
Given Policies (minimum support)
The system must be capable of flagging violating expenses based on these example policies:
- No restaurant expense over $75.
- No airfare expenses.
- No entertainment expenses.
- No expense over $250.
AI interview prep
Core dilemma
The central engineering conflict is balancing the need for a highly flexible, expressive, and dynamic rule definition system with the requirements for high-performance, scalable, and auditable rule evaluation, especially when dealing with potentially conflicting business logic.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design expense rules engine and return type
Design a Rules Engine for Corporate Card Expenses
Context
You are tasked with building an expense policy engine for a corporate credit-card system. In this system, managers define policies (referred to as rules) that must be evaluated against individual expense transactions. Each expense transaction is represented as a dictionary or map, where both keys and values are strings.
Task
Your design and description should cover the implementation of the following:
- Rule Representation: Define a structure for rules that can support at least the four sample policies provided below and is scalable to hundreds of rules.
- Evaluation Function: Design a function with the signature
evaluateRules(rules: list <rule>, expenses: list <expense>) -> ?. - API Response: Clearly define the return type of the
evaluateRulesfunction as an API response suitable for consumption by downstream services and user interfaces. - Key Considerations: Explain your approach to:
- Conflict handling and rule precedence.
- Auditing and providing explanations for rule violations.
- Performance and scalability of the system.
- How managers select, create, and manage rules within the system.
- Assumptions & Clarifications: State any assumptions you make and product clarifications you would seek before proceeding with implementation.
Given Policies (minimum support)
The system must be capable of flagging violating expenses based on these example policies:
- No restaurant expense over $75.
- No airfare expenses.
- No entertainment expenses.
- No expense over $250.