Design a delivery cost system
Company: Rippling
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
##### Question
Design an object-oriented, in-memory **Delivery Cost System** for a food-delivery company. Drivers register with an hourly rate, deliveries are recorded as they complete, and the system reports cost and payment metrics for a live dashboard.
Implement the following:
1. **`registerDriver(driverId, hourlyRate)`** — Add or update (upsert) a driver and their hourly rate. Drivers may have different rates. Decide whether a rate change should affect already-recorded deliveries.
2. **`recordDelivery(driverId, startTime, endTime)`** — Record one completed delivery. Cost accrues as `hourlyRate(driverId) x duration`. Deliveries are recorded immediately after completion and last no more than 3 hours. A single driver may have overlapping deliveries, and each is paid independently. Define interval semantics (inclusive/exclusive endpoints), how partial hours are prorated, and the time representation (require at least one-second precision).
3. **`getTotalCost()`** — Return the aggregated cost of all recorded deliveries across all drivers. This drives a live dashboard, so it should be cheap to call.
4. **`payUpTo(timestamp)`** — Mark all accrued cost up to the given timestamp as paid. A delivery that straddles the timestamp should have only the portion up to the timestamp counted as paid. Repeated or earlier calls must be idempotent.
5. **`getTotalUnpaid()`** — Return the remaining unpaid amount.
6. **`maxSimultaneousDriversInPast24Hours()`** — Return the maximum number of drivers that were simultaneously on a delivery at any instant within the last 24 hours.
Discuss your class design, core data structures, method signatures, numeric precision (avoiding floating-point money errors), rounding, time-zone handling, thread-safety for a concurrent dashboard, idempotency, and the time/space complexity of each operation.
Quick Answer: A Rippling software-engineer system-design screen: build an object-oriented, in-memory delivery cost system that registers drivers with hourly rates, records deliveries, and reports total cost, paid/unpaid amounts via an idempotent payUpTo cutoff, and the max number of drivers simultaneously delivering in the last 24 hours. It tests time-interval modeling, exact monetary arithmetic, sweep-line concurrency, idempotency, time-zone handling, and thread-safe dashboard reads.