Customer Revenue Management API: Design CRUD Endpoints for Accounts and Revenue Records
Question Details
Round 1 Coding / System Design
Problem
Design and partially implement a REST API for managing customer revenue data. The system tracks Account and RevenueRecord entities:
Account: {id, name, tier: ["free"|"pro"|"enterprise"], created_at}
RevenueRecord: {id, account_id, amount, currency, period_start, period_end}
Required endpoints:
- POST /accounts — create account
- GET /accounts/{id}/revenue —
return all revenue records, with optional ?period=YYYY-MM filter
- GET /accounts/{id}/revenue/summary —
return total revenue, avg per period, and MoM growth
- DELETE /accounts/{id} — soft-delete account and all associated records
python
# Pseudo-schema
class AccountRouter:
def create_account(self, name: str, tier: str) -> Account: ...
def get_revenue(self, account_id: str, period: str | None) -> list[RevenueRecord]: ...
def get_summary(self, account_id: str) -> dict: ...
def delete_account(self, account_id: str) -> None: ...
Follow-ups
- How do you implement MoM growth when some months have no revenue? What do you return for a null denominator?
- Describe your DB schema, including indexes. Which columns need indexes for the period filter to be efficient?
- The
DELETEis soft-delete. How do allGETendpoints need to change to respect deleted records? - A finance team needs to export 5 years of revenue for all enterprise accounts as CSV. How does your API handle bulk export without timing out?
Full Details
Round 1 Coding / System Design
Problem
Design and partially implement a REST API for managing customer revenue data. The system tracks Account and RevenueRecord entities:
Account: {id, name, tier: ["free"|"pro"|"enterprise"], created_at}
RevenueRecord: {id, account_id, amount, currency, period_start, period_end}
Required endpoints:
- POST /accounts — create account
- GET /accounts/{id}/revenue —
return all revenue records, with optional ?period=YYYY-MM filter
- GET /accounts/{id}/revenue/summary —
return total revenue, avg per period, and MoM growth
- DELETE /accounts/{id} — soft-delete account and all associated records
python
# Pseudo-schema
class AccountRouter:
def create_account(self, name: str, tier: str) -> Account: ...
def get_revenue(self, account_id: str, period: str | None) -> list[RevenueRecord]: ...
def get_summary(self, account_id: str) -> dict: ...
def delete_account(self, account_id: str) -> None: ...
Follow-ups
- How do you implement MoM growth when some months have no revenue? What do you return for a null denominator?
- Describe your DB schema, including indexes. Which columns need indexes for the period filter to be efficient?
- The
DELETEis soft-delete. How do allGETendpoints need to change to respect deleted records? - A finance team needs to export 5 years of revenue for all enterprise accounts as CSV. How does your API handle bulk export without timing out?