Debug Portfolio Totals That Drift by Fractions of a Cent
Last updated: November 29, 2026
Quick Overview
Customers report that the portfolio total in the app differs by a cent from the sum of their individual asset values. Find the likely causes and fix the calculation so totals and line items always agree.
Coinbase
November 29, 20260
0
0 solved
Customers report that the portfolio total in the app differs by a cent from the sum of their individual asset values. Find the likely causes and fix the calculation so totals and line items always agree.
Coinbase shows fiat values for crypto balances with up to 18 decimals, and support tickets about mismatched cents erode trust. The interviewer checks that you recognize float representation error and inconsistent rounding, and that you know practical fixes such as integer units, Decimal and allocation methods.
What the Interviewer Expects
- Reproduce the bug with a minimal float example
- Explain binary floating point cannot represent 0.1 exactly
- Use integer base units and Decimal for conversions
- Round once, at a defined point, with a defined mode
- Show how to split an amount so parts sum to the total
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Should the total be the sum of rounded lines or the rounded sum of exact values?
- How would you write a property-based test for this?
- Where in the stack (database, backend, client) should rounding happen?
- How do you handle currencies with zero decimal places like JPY?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Fiat values of each position and the portfolio total must be consistent, stable across devices and exact to the cent. Inputs are crypto quantities in base units, prices as decimal strings and fiat amo...
High-Level Design
Diagnosis: the client summed float values, so 0.10 added ten times plus 0.20 gives 1.2000000000000002, and line items were rounded half-up on one platform and half-even on another. Fix: keep crypto in...