Katkat

Implement GPU credit ledger

OpenAISoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's ability to design efficient stateful systems and algorithmic data structures for tracking per-tenant resource balances, including handling idempotency, negative balance policies, concurrency, and persistence.

You manage a GPU pool with per-tenant credits. Given a list/stream of events where each event adjusts a tenant’s credit balance by a signed integer (positive = add credit, negative = deduct credit), implement three functions: (

  1. init(events): initialize internal state by applying the given ordered events; (
  2. getBalance(tenantId): return the current credit balance for the specified tenant; (
  3. applyEvent(event): process a new single event and update state. Define the event schema (tenantId, delta, optional timestamp/id), decide whether to reject events that would drive balances below zero or allow negatives, and handle idempotency if event ids repeat. Aim for O(
  4. average time per operation after O(n) initialization, and discuss data structures, concurrency considerations, and how you would persist state for crash recovery.