Add inventory logs that describe trades from the system’s side rather than the client’s. Explain exact fractional quantities, committed versus attempted actions, transaction-bound audit records, and deduplication of retried operations.
Log Inventory Changes from the System’s Perspective
Company: Robinhood
Role: Backend Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
A share-inventory system processes client purchases and sales. Add logs that record changes from the system's perspective: for example, when a client buys one share from the system, the system log records a sale of one share.
Explain where logging belongs in the transaction flow and how to keep the recorded action, quantity, and resulting inventory consistent. The underlying fractional-share execution rules and starter code are not supplied; do not invent them.
### Constraints & Assumptions
- Client and system directions are opposite for a trade between them.
- Quantities may be fractional, so arithmetic and formatting must preserve the agreed precision.
- Clarify whether the log records attempted actions, committed inventory changes, or both.
### Clarifying Questions to Ask
- Is this an audit record that must commit with inventory, or a best-effort diagnostic log?
- What identifies a repeated client request and a committed trade?
- How are rejected or partially completed trades represented by the existing system?
```hint
Logging before a transaction commits can describe a sale that never actually happened.
```
### What a Strong Answer Covers
Define the perspective and event meaning, place logging at a reliable state boundary, and preserve stable transaction identity. Explain precision, duplicate processing, and the distinction between an attempted operation and a committed inventory effect.
### Follow-up Questions
- What would a client sale look like in the system log?
- How would a retry avoid creating a second audit event for the same committed trade?
Overview: Add inventory logs that describe trades from the system’s side rather than the client’s. Explain exact fractional quantities, committed versus attempted actions, transaction-bound audit records, and deduplication of retried operations.
A share-inventory system processes client purchases and sales. Add logs that record changes from the system's perspective: for example, when a client buys one share from the system, the system log records a sale of one share.
Explain where logging belongs in the transaction flow and how to keep the recorded action, quantity, and resulting inventory consistent. The underlying fractional-share execution rules and starter code are not supplied; do not invent them.
Constraints & Assumptions
Client and system directions are opposite for a trade between them.
Quantities may be fractional, so arithmetic and formatting must preserve the agreed precision.
Clarify whether the log records attempted actions, committed inventory changes, or both.
Clarifying Questions to Ask Guidance
Is this an audit record that must commit with inventory, or a best-effort diagnostic log?
What identifies a repeated client request and a committed trade?
How are rejected or partially completed trades represented by the existing system?
What a Strong Answer Covers Guidance
Define the perspective and event meaning, place logging at a reliable state boundary, and preserve stable transaction identity. Explain precision, duplicate processing, and the distinction between an attempted operation and a committed inventory effect.
Follow-up Questions Guidance
What would a client sale look like in the system log?
How would a retry avoid creating a second audit event for the same committed trade?