Prevent Budget Overspend Under Concurrent Approvals

Last updated: November 29, 2026

Quick Overview

Several purchase requests against the same department budget can be approved at nearly the same moment. Design and implement a budget ledger that reserves funds at approval, converts reservations to actual spend when invoiced, releases them on cancellation, and never lets concurrent approvals exceed the limit.

ZipHQ
Software Engineering Fundamentals
Software Engineer
ZipHQ
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Several purchase requests against the same department budget can be approved at nearly the same moment. Design and implement a budget ledger that reserves funds at approval, converts reservations to actual spend when invoiced, releases them on cancellation, and never lets concurrent approvals exceed the limit.

Budget checks are part of Zip's approval workflows, and a race between two approvers can silently overspend a budget a finance team trusted. Interviewers look for an understanding of check-then-act races, idempotent retries, and how the in-memory reasoning maps onto database locking.

What the Interviewer Expects
  • Identify the check-then-act race in a naive read, compare, write
  • Hold a lock (or a row lock) across the availability check and the update
  • Make reserve idempotent on a request id so retries do not double reserve
  • Model reserved and spent separately
  • Translate the design to SQL: `SELECT ... FOR UPDATE` or a conditional `UPDATE`
Key Topics to Cover
race conditions
locking
idempotency
ledger design
transactions
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you do this with a single conditional UPDATE instead of explicit locks?
  • What happens when the final invoice exceeds the reserved amount?
  • How do you handle a request split across two budgets atomically?
  • How would you reconcile with the ERP if it is the source of truth for actuals?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Operations: reserve(request_id, budget, cents), release(request_id), capture(request_id, actual). Invariant: reserved plus spent never exceeds the limit at reserve time. Retrying a reserve with ...

High-Level Design

Keep limit, reserved, spent per budget and a holds map from request to (budget, amount). One lock per budget serializes mutations to that budget without blocking others. Money is integer cents...


Submit Your Answer
Markdown supported

Related Questions