This question is deeply rooted in Stripe's actual business operations in Brazil. It evaluates a candidate's ability to handle state management, timeline overlaps, and complex business logic modeling.
Problem Description
In Brazil, credit card receivables are treated as financial assets that can be registered and traded. Stripe is required by regulations to report these receivables to a central Registry.
Part 1: Register Receivables
Given a transaction (Charge), you need to convert it into a "Receivable Unit". A Charge typically contains:
amount: Transaction valuepayout_date: Expected date of funds availabilitystatus: e.g., pending, paid
You need to implement a function to register this Charge with the Registry. Upon success, the Registry returns a unique receivable_id.
Part 2: Contracts & Updates
Merchants may sign "Prepayment Contracts" with banks, using their future receivables as collateral to get cash immediately. This introduces a "Locking" concept: Once a Receivable is locked by a Contract, Stripe cannot modify it (e.g., changing the payout date or amount) without specific handling.
Input Streams:
Charge Updates: Amount or date changes.Contract Events: Contracts being signed or cancelled.
The Challenge: When receiving a Charge Update, you must check if the corresponding Receivable is covered by any Active Contract.
- If No Contract: Update the Registry directly.
- If Contract Exists: Reject the update, or handle it via split logic (depending on specific requirements).
oavoservice Solution Analysis
The core difficulty lies in Data Consistency and State Validation.
1. Entity Modeling
Define clear classes:
class Charge:
id: str
amount: int
payout_date: str
class Receivable:
id: str # ID from Registry
charge_id: str
amount: int
status: str
class Contract:
id: str
target_charge_ids: List[str]
status: str # ACTIVE, CANCELLED
2. Conflict Detection Logic
When processing a Charge Update, perform a "Pre-check":
- Find the
receivable_idlinked to thecharge_id. - Query the
ContractRepositoryfor anystatus == ACTIVEcontract that includes thisreceivable_id. - Key Detail: Watch out for time-based locks. Some variations only lock receivables within a specific date range.
3. Idempotency & Retries
Communication with the Registry might fail.
- Question: What if the Registry API times out?
- Solution: Use a State Machine or Retry Queue. Persist a
PENDING_REGISTRYstate and use a background job to retry.
Overwhelmed by Business Logic?
Stripe interview questions are full of "detail traps." oavoservice mentors are senior engineers who know exactly how to deconstruct these complex requirements into simple CRUD + State Check logic.
- Scenario Simulation: Replicate real API interactions.
- Code Simplicity: Learn to write elegant code that solves the problem without over-engineering.