Aggregate balance summaries and post a reconciliation
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Oct 2024. It tests api integration, json and aggregation.
An integration exercise in an existing Python repository (FastAPI, pytest), done in steps that build on each other.
Part 1: parse and print one summary
Read a JSON balance-summary file and print its contents in a readable form.
Part 2: aggregate several files
Read several balance-summary files and combine them into one total, for example per currency.
Part 3: reconcile and post
Combine the aggregated totals with reconciliation data, then send the processed result to an API with a POST request.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
load_summary(path) -> Summary,aggregate(summaries) -> Totals,reconcile(totals, reconciliation) -> Report,post_report(report, client) -> Response. - A summary looks like
{"account": "acct_1", "balances": [{"currency": "usd", "available": 1200, "pending": 300}]}, with amounts in minor units (cents).
Example
summary_1.json: {"account": "acct_1", "balances": [{"currency": "usd", "available": 1200, "pending": 300}]}
summary_2.json: {"account": "acct_2", "balances": [{"currency": "usd", "available": 800, "pending": 0},
{"currency": "eur", "available": 500, "pending": 50}]}
aggregate -> {"usd": {"available": 2000, "pending": 300}, "eur": {"available": 500, "pending": 50}}
reconciliation: {"usd": {"expected_available": 2100}}
report -> {"usd": {"available": 2000, "expected": 2100, "difference": -100}, ...}
POST /reconciliations with the report
Constraints
- About 75 minutes, in an unfamiliar repository.
- Keep parsing, aggregation and network code in separate, testable functions.
Clarifying questions
- What is the exact schema of a summary file? Can fields be missing?
- Are amounts in minor units? Can currencies be mixed in one total?
- What should happen when one file is malformed: skip it, or fail the run?
- What does the API expect, and how should a failed POST be handled?
What a strong answer covers
- Reading the docs and existing code before writing anything, and following its patterns.
- Integer amounts (no floats for money) and totals kept per currency.
- Clear handling of malformed files and missing fields.
- A POST with the right headers, a check of the response status, and retry or error reporting on failure.
- Tests for parsing, aggregation and reconciliation without the network, plus a mocked POST.
Follow-ups
- There are thousands of summary files. Process them in a stream.
- Make the POST safe to retry (an idempotency key).
- Report which accounts cause each difference.
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Oct 202460 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
What it tests
api integration · json · aggregation
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
