PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/OpenAI

Design credit balance with vector-clock expirations

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of distributed-systems concepts such as vector clocks, partial orders, concurrency control and idempotency, plus practical competencies in data structures and algorithms for efficient per-user state management and correctness under concurrent operations.

  • hard
  • OpenAI
  • System Design
  • Software Engineer

Design credit balance with vector-clock expirations

Company: OpenAI

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

Design and implement a credit balance service that processes a stream of operations for each user. Operations: ( 1) add(userId, creditId, amount, expiryVc) adds credits with an expiry time represented by a vector clock; ( 2) use(userId, amount, atVc) spends credits at logical time 'atVc'. Rules: spending must consume from the credits that expire soonest; any credit whose expiryVc is <= atVc is unavailable; expired credits cannot be used. Assume every operation is tagged only with a vector clock; wall-clock time is not used. Specify APIs, core data structures, and algorithms to support efficient inserts and spends across many active credits. Explain how you compare vector-clock expiries with 'atVc' and impose a deterministic ordering when vector clocks are partially ordered (e.g., tie-break policies). Describe safeguards against double-spend and against using expired credits, and how to handle identical expiries. Provide complexity analysis and walk through test cases, including tricky edge cases (concurrent expiries, expiry exactly at 'atVc', zero/negative amounts, insufficient balance).

Quick Answer: This question evaluates understanding of distributed-systems concepts such as vector clocks, partial orders, concurrency control and idempotency, plus practical competencies in data structures and algorithms for efficient per-user state management and correctness under concurrent operations.

Related Interview Questions

  • Design Video Generation Orchestration - OpenAI (medium)
  • Design CI/CD Build Caching - OpenAI
  • Design an Instagram-like Feed System - OpenAI (medium)
  • Design Online Chess Matchmaking - OpenAI (hard)
  • Design Android MVVM API Architecture - OpenAI (medium)
OpenAI logo
OpenAI
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
10
0

Credit Balance Service with Vector-Clock Expiries

You are designing a backend service that maintains per-user promotional credits. Credits are granted as independent buckets, each with an expiry time represented by a vector clock (no wall-clock time exists). Clients issue operations with an attached vector clock.

Implement the service and explain your design.

Operations

  1. add(userId, creditId, amount, expiryVc)
    • Adds a credit bucket with a unique creditId, positive amount, and an expiry represented by a vector clock expiryVc.
  2. use(userId, amount, atVc)
    • Spends credits at logical time atVc. The service must consume from credits that expire soonest first.
    • A credit is unavailable (expired) for this spend if expiryVc <= atVc under vector-clock partial order. Expired credits cannot be used.

Requirements

  • Specify APIs (request/response, idempotency), core data structures, and algorithms to support efficient inserts and spends across many active credits per user.
  • Define how you compare vector clocks (<=, <, ==, concurrent) and how you impose a deterministic total order among credits when expiries are partially ordered (concurrent). State tie-break policies.
  • Describe safeguards against double-spend, against using expired credits, and how you handle identical expiries.
  • Provide complexity analysis.
  • Walk through test cases, including edge cases: concurrent expiries, expiry exactly at atVc, identical expiries, zero/negative amounts, insufficient balance.

Assumptions you may make:

  • Vector clocks are maps from processId -> integer counter; missing components are treated as 0.
  • The service processes operations per user on a single shard/actor (or uses equivalent transactional concurrency control) so that each user's operations are linearizable.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.