Square logo

Square Hard Interview Questions

1 hard-level practice questions for Square technical interviews

Square software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer

No verified questions yet for Square.

system design Hard api design #1

1. Design OfflinePOS — reconcile queued Square POS payments and refunds


Background
Square sellers need to keep recording sales when a point-of-sale terminal loses connectivity. Design an in-memory model of the merchant-side reconciliation logic: terminals queue payment and refund operations offline, then synchronize against shared order balances. This exercise models bookkeeping only, not card authorization, and its reconciliation policies are exercise-specific rather than claims about Square's production behavior.
Requirements
1. Orders and offline queues: Create orders with positive integer totals in cents. Each terminal has a FIFO queue. Enqueuing an operation must not change an order's balances; only sync can do so. All orders must be created before operations referencing them are queued.
2. Global idempotency: An operation ID is unique across all terminals and operation types. Enqueuing a new ID returns "QUEUED". Reusing an ID with exactly the same terminal, operation type, order, amount, and referenced payment returns "DUPLICATE", without re-enqueuing it. Reusing it with any different field returns "CONFLICT". Retain IDs even after rejection. For a previously seen operation ID, perform this identity check before validating the new payload.
3. Payment reconciliation: sync(device_id) processes that terminal's pending operations in FIFO order and removes them from its queue. A payment is applied only if captured_cents + amount_cents <= total_cents; otherwise reject it with "PAYMENT_LIMIT". Accept or reject the entire operation, never a portion. When terminals compete, the order in which sync is called determines the winner.
4. Refund reconciliation: A refund references a payment's operation ID. That payment must already have been applied to the same order when the refund is processed; otherwise reject the refund with "UNKNOWN_PAYMENT". Refunds against one payment may cumulatively total at most its captured amount; exceeding that amount produces "REFUND_LIMIT". Successful operations return "APPLIED". Rejections are final: a corrected attempt requires a new operation ID.
5. Balances and results: Track cumulative captured and refunded amounts separately. Refunds do not reopen an order for additional payments: due_cents = total_cents - captured_cents, and net_cents = captured_cents - refunded_cents. Each sync returns a list of {"operation_id": string, "status": string} results. Syncing an empty or unknown terminal returns []. Returned results and order snapshots must not expose mutable internal state.
6. Validation and execution model: Empty identifiers, nonpositive amounts or totals, duplicate order creation, and references to nonexistent orders raise ValueError without changing state. A refund may be queued before its referenced payment exists. Methods execute sequentially; synchronization is explicit, synchronous, and has no simulated transport failures.
Class API
  • OfflinePOS() — Construct an empty merchant reconciliation model.

  • create_order(order_id: str, total_cents: int) -> None — Register an order; duplicate order IDs are invalid.

  • queue_payment(device_id: str, operation_id: str, order_id: str, amount_cents: int) -> str — Queue a payment, returning QUEUED, DUPLICATE, or CONFLICT.

  • queue_refund(device_id: str, operation_id: str, order_id: str, payment_id: str, amount_cents: int) -> str — Queue a refund with the same enqueue-result semantics.

  • sync(device_id: str) -> list[dict[str, str]] — Reconcile and drain one terminal's queue.

  • get_order(order_id: str) -> dict[str, int] — Return total_cents, captured_cents, refunded_cents, due_cents, and net_cents.


Example 1:
Input sequence on a new instance:
[
  {"method": "create_order", "args": ["order-1", 1000]},
  {"method": "queue_payment", "args": ["terminal-A", "pay-1", "order-1", 600]},
  {"method": "queue_payment", "args": ["terminal-B", "pay-2", "order-1", 500]},
  {"method": "sync", "args": ["terminal-A"]},
  {"method": "sync", "args": ["terminal-B"]},
  {"method": "queue_payment", "args": ["terminal-B", "pay-3", "order-1", 400]},
  {"method": "sync", "args": ["terminal-B"]},
  {"method": "get_order", "args": ["order-1"]}
]

Output, one entry per method call:
[
  null,
  "QUEUED",
  "QUEUED",
  [{"operation_id": "pay-1", "status": "APPLIED"}],
  [{"operation_id": "pay-2", "status": "PAYMENT_LIMIT"}],
  "QUEUED",
  [{"operation_id": "pay-3", "status": "APPLIED"}],
  {"total_cents": 1000, "captured_cents": 1000, "refunded_cents": 0, "due_cents": 0, "net_cents": 1000}
]

Explanation: Terminal A captures 600 cents first. Terminal B's 500-cent operation would make the captured total 1100, so it is rejected. A new 400-cent operation brings the captured total to exactly 1000 cents.
Constraints
  • At most 100,000 orders, 100,000 distinct operations, and 100,000 terminals per instance; identifier lengths are 1–64 characters.

  • Totals and operation amounts are integers from 1 through 10^12 cents. Parameter types and upper bounds are guaranteed; implement the validation explicitly required above.

  • All calls are sequential. Use memory only; no database, threads, network calls, or payment-provider integration is required.

  • Target expected O(1) enqueue and balance-query time, and O(k) time to synchronize k pending operations.
Want to practise this one?
Create a free account to open the full question and practise Square questions with AI.
Sign up free

Start practicing Square questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free