InterviewDB
Experience
Billing System: Generate and Manage Invoices with Line Items and Tax Calculation
phone
Interview Experience
Round 1 Coding
Problem
Design a billing system that creates invoices, adds line items, applies discounts, and computes totals with tax.
python
class LineItem:
def __init__(self, description: str, quantity: int, unit_price: float):
...
class Invoice:
def __init__(self, invoice_id: str, customer: str, tax_rate: float):
...
def add_item(self, item: LineItem) -> None:
...
def apply_discount(self, percent: float) -> None: # on subtotal
...
def subtotal(self) -> float:
...
def total(self) -> float: # after discount and tax
...
def summary(self) -> str:
...
Example
inv = Invoice("INV-001", "Acme Corp", tax_rate=0.08)
inv.add_item(LineItem("Widget", 5, 10.00))
inv.add_item(LineItem("Gadget", 2, 25.00))
inv.subtotal() -> 100.0 # 5*10 + 2*25
inv.apply_discount(10) # 10% off
inv.total() -> 97.20 # 90 * 1.08
Follow-ups
- How do you handle discounts that apply only to specific line items versus the entire invoice?
- How would you represent recurring invoices that auto-generate monthly?
- What happens if
apply_discountis called multiple times — do they stack or replace? - How do you serialize an invoice to JSON for API responses?
Full Details
Round 1 Coding
Problem
Design a billing system that creates invoices, adds line items, applies discounts, and computes totals with tax.
python
class LineItem:
def __init__(self, description: str, quantity: int, unit_price: float):
...
class Invoice:
def __init__(self, invoice_id: str, customer: str, tax_rate: float):
...
def add_item(self, item: LineItem) -> None:
...
def apply_discount(self, percent: float) -> None: # on subtotal
...
def subtotal(self) -> float:
...
def total(self) -> float: # after discount and tax
...
def summary(self) -> str:
...
Example
inv = Invoice("INV-001", "Acme Corp", tax_rate=0.08)
inv.add_item(LineItem("Widget", 5, 10.00))
inv.add_item(LineItem("Gadget", 2, 25.00))
inv.subtotal() -> 100.0 # 5*10 + 2*25
inv.apply_discount(10) # 10% off
inv.total() -> 97.20 # 90 * 1.08
Follow-ups
- How do you handle discounts that apply only to specific line items versus the entire invoice?
- How would you represent recurring invoices that auto-generate monthly?
- What happens if
apply_discountis called multiple times — do they stack or replace? - How do you serialize an invoice to JSON for API responses?
Free preview. Unlock all MongoDB questions →
About This Question
This is a candidate experience report from a mongodb interview during the phone round.