Amazon SDE-2 LLD round . Could not answer follow-up question. Inputs appreciated. !!
Summary
I interviewed for an SDE‑2 role and was asked to design a simple rule engine for credit‑card expenses; I was unable to answer the follow‑up scalability question.
Full Experience
Problem statement given
Design a simple rule engine that:
- Takes a list of credit card expenses
- Applies a set of rules
- Flags the expenses that needs review
- More rules can be added in future.
- Design needs to be maintainable.
Example Rules
- Restaurant expenses should not exceed 70 dollar.
- Airfare expenses should not be allowed.
- Any expense above 250 dollar should be flagged.
My Approach (Simple Version)
I modeled each rule as an independent unit and created a rule engine to execute them.
Each rule implements a common interface:
interface Rule {
RuleResult evaluate(Expense expense);
}
The engine iterates through all expenses and applies all rules:
for each expense:
for each rule:
evaluate rule
if rule says SKIP → stop processing this expense
if rule says FLAG → mark it
finally, return all flagged expenses.
Followup question by interviewer was
If we keep adding more rules in the future, we’ll end up creating a new class for every rule.
- Won’t this lead to too many classes (class explosion)?
- How would you redesign this to keep it scalable and maintainable?
Would love to hear how others would approach this - especially in real‑world systems.
Interview Questions (1)
Design a Simple Rule Engine for Expense Validation
Design a simple rule engine that:
- Takes a list of credit card expenses
- Applies a set of rules
- Flags the expenses that needs review
- More rules can be added in future.
- Design needs to be maintainable.
Example Rules
- Restaurant expenses should not exceed 70 dollars.
- Airfare expenses should not be allowed.
- Any expense above 250 dollars should be flagged.
Follow‑up scalability question: If we keep adding more rules, we’ll end up creating a new class for every rule. Won’t this lead to class explosion? How would you redesign this to keep it scalable and maintainable?