The interview problem
A tenant may consume at most 1,000 job-admission units during a fixed quota period across three regions. Regions must admit locally during network partitions, but total admitted cost must never exceed the limit. Design regional budget allocation and transfer, including a lost transfer acknowledgement.
Original system-design practice, not a reported company interview. Numbers are hypothetical. Primary database documentation retrieved September 27, 2026; interview date not applicable.
1. Define the conserved resource
Choose a fixed quota period and integer admission costs. In this exercise an accepted job consumes its reserved cost even if it later fails; refunds are outside the initial contract. The limit concerns admissions, not simultaneous jobs or requests per second. A job costing more than the region's free balance must wait, transfer budget or be rejected.
Let C be committed consumed units, F the sum of free regional units, U unallocated units and T committed transfers not yet credited at their destination. Maintain C + F + U + T = 1,000, with every term nonnegative. Individual units cannot be spendable in two regions. With concurrent observations, a dashboard may not show a consistent global sum; the invariant is a protocol property, not a sum of stale monitoring snapshots.
Global hard limits and independent full regional budgets are incompatible. Partition tolerance here means a region can spend its already assigned balance. It does not mean every region can always admit whenever some other region has unused quota.
2. Separate allocation from local admission
tenant-period authority: total limit and initial grants
↓
regional durable balance and admission ledger
↓
atomic debit + job admission + outbox
↓
idempotent job execution
regional transfer debit → durable transfer record → destination creditIdentify every balance by tenant, quota period and region. Issue initial grants through a strongly consistent allocator that cannot mint more than the total. Atomically debit its unallocated pool and create a grant record, then credit the recipient idempotently using the same debit-before-credit protocol as regional transfers; initial grants in flight also belong in T. Each region uses a single authoritative durable transaction domain for its free balance and operation records. Replication and failover must preserve committed debits; a stale restored database is not safe to resume spending from.
An admission transaction checks a nonnegative remaining balance, debits cost and records the logical operation ID with its result. Duplicate requests return the existing result without another debit. Bind each logical operation to a stable home region, and route retries there; local deduplication alone cannot identify an admission committed in another partitioned region. If the home region is unreachable, report an unknown outcome or wait rather than re-admitting elsewhere. A home-region reassignment requires reconciled state and fencing of the old writer. Store a job or outbox entry in that same transaction. A crash after debit but before dispatch leaves durable work to retry; the worker must also prevent duplicate business effects.
Serializable transactions or a correctly locked balance row can protect local invariants. PostgreSQL documents that serialization failures require retry handling. Local database isolation is only a building block: it does not make a cross-region transfer atomic or fence two independent restored copies of the same balance.
3. Transfer with debit before credit
Give regions A, B and C initial balances 400, 350 and 250. A admits 300 units, leaving 100; B admits 100, leaving 250; C admits none, leaving 250. Consumed units total 400 and free units total 600.
A needs more capacity, so B transfers 150. In one B transaction, reduce its free balance from 250 to 100 and create immutable transfer record X with tenant, period, source, destination and amount. This record authorizes the transfer. Now free balances sum to 450 and in-transit units are 150: 400 + 450 + 150 = 1,000.
Deliver X through an authenticated internal channel. A atomically inserts X into a unique received-transfer table and increases its free balance from 100 to 250. The destination transaction moves the 150 units from logically in transit to credited. Repeated deliveries of X have no additional effect. Validate all immutable fields on duplicate receipt; reusing an ID with a different amount is an error.
If A's acknowledgement is lost, B must not restore its 150 units. B retries delivery or queries the durable result for X. Its local transfer status may remain uncertain while A has already credited the balance; that uncertainty does not create spendable units at B. An acknowledgement is useful for cleanup, not permission to refund a timeout.
4. Do not reclaim ambiguous grants by time alone
The simplest protocol makes a committed transfer irrevocable. If it was sent to the wrong region, the destination can initiate a new transfer of free units after crediting it. This avoids a cancel-versus-credit race. A design supporting cancellation needs an authoritative mutually exclusive decision between cancellation and credit, not two independently timed actions.
During a partition, B's committed 150 may be stranded until A can receive it. This reduces availability but preserves the hard limit. Expiring a message, failing to see an acknowledgement or declaring a region unhealthy does not prove that the destination did not spend the grant.
Similarly, do not reclaim all budget from an unreachable region while it can still admit locally. A lease design would need trusted expiry enforcement and fencing at every spending path, including failover; merely recording an expiry in a control-plane database is insufficient. For the initial design, leave unreachable balances assigned and fail closed when local budget is exhausted.
5. Make allocation size an explicit trade-off
After the completed transfer, A has 250 free units and B has 100. If A alone receives 300 one-unit jobs during a partition, it admits 250 and rejects or queues 50 despite C still holding 250. The rejected workload is not evidence that the invariant failed; it exposes stranded capacity under the chosen allocation.
For a larger tenant processing 10,000 one-unit admissions per second, replenishing in batches of 1,000 units would require roughly ten successful grant deliveries per second in steady state. Batches of 100 require roughly 100 deliveries per second. These estimates assume sufficient unallocated or transferable capacity and do not reduce the 10,000 local durable admissions per second.
Larger grants reduce coordination traffic but strand more capacity when a region becomes unreachable. Allocate according to forecast demand while retaining a central reserve, and rebalance only free units. Forecasts affect availability and utilization, not authority to exceed the tenant's limit.
6. Fence periods, retries and policy changes
Include the quota-period identifier in every grant, transfer and admission record. Never credit an old-period transfer into a new-period balance. Define whether a delayed job is charged at initial admission or execution; here it is charged at admission, and execution retries retain that admission identity.
Assign new requests to periods using a trusted policy clock or authoritative period token with an explicit clock-error policy. A client cannot choose yesterday's period to obtain unused quota. Closing old admission paths must be enforced consistently; do not promise exact wall-clock boundaries from unsynchronized local clocks.
If the limit is reduced below already consumed plus outstanding allocated authority, the new lower cap cannot be retroactively enforced. Stage the reduction for a future period, stop new grants and reclaim confirmed free units, or explicitly report the remaining unavoidable exposure. Raising a limit also requires an authorized, idempotent mint operation.
Retain transfer deduplication and admission records for the full replay horizon. A backup restoration that forgets a debit or received-transfer ID can create extra spending authority. Recover from an authoritative ledger and fence old writers before reopening admission; uncertain state is a reason to stop, not initialize a fresh full balance.
7. Failure drills and self-review
Test simultaneous local debits, lost destination acknowledgements, duplicate transfers, reused transfer IDs, a crash before outbox dispatch, stale regional restoration and cross-period replay. Monitor free capacity, uncredited transfers, denied demand and deduplication conflicts separately from reported consumption.
Trade-offs: Regional allocation lowers admission latency but sacrifices perfect utilization during partitions. Irrevocable transfers simplify safety but can temporarily strand units. Exact durable admissions cost more than approximate counters. Adding refunds requires a separate once-only accounting transition with a defensible definition of refundable work.
Follow-ups: Can a lost acknowledgement justify a refund? No. Does a transfer create quota? No, it moves existing authority. Does serializable isolation solve cross-region double spending by itself? No. Can unused remote capacity guarantee local admission during a partition? Not under this hard-limit design.
Score 0–2 each for conservation invariant, atomic admission, debit-before-credit transfer, ambiguous-outcome handling and period/failover fencing. A strong answer explains where availability is deliberately lost to preserve the cap.
Show the cost of preserving a hard cap
Additional original practice exercise · October 3, 2026. Numbers are illustrative assumptions.
Take 1,000 total units: 400 consumed, 450 free and 150 in transit. The destination is unreachable. Even if a dashboard shows no credit there, the source cannot put 150 back into its spendable balance: the destination might already have committed the credit. Only durable evidence from the transfer protocol resolves that uncertainty.
If demand needs 600 more units before connectivity returns, this state permits at most 450 additional admissions across reachable free balances. The remaining demand must wait or fail, even though 150 units are not yet observed as consumed. Local availability depends on the placement of those 450 units as well as their global total.
Practice: the quota period changes before delivery. Reject credit to the new period and retain the old transfer identity for reconciliation. Discarding the old record and reissuing its amount as a new grant would silently change the accounting contract.
Related practice: Design a lease service with fencing tokens · Design a GPU job scheduler
Sources and next steps
- PostgreSQL 17: transaction isolation — local concurrency guarantees and serialization-retry requirements; publication date not established.
The regional allocation and transfer protocol is an original design proposal, not a database-provided distributed guarantee. Continue with rate limiting for traffic pacing and distributed semaphores for concurrent-work limits.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.