All practice tasks

Coding (Platform)

Resolve Checkout Conflicts

React · Hard · Optimistic Updates

A support agent edits quantities in an existing checkout while another operator can change the same order on the server. The supplied screen updates immediately but loses concurrent row updates and discards the agent’s intended quantity after a conflict. Repair state reconciliation without silently overwriting newer server data.

Task

Keep optimistic updates independent per row. On a version conflict show the server quantity and retain the agent’s requested quantity for an explicit retry or discard.

Contract

  • Component props: CheckoutApp receives initialLines and api. initialLines is read only and stable for the mounted checkout. Each line is {id,title,quantity,version}. IDs are unique; quantity is 1..20 and version is a positive integer.
  • Provided update API: api.update(id,{quantity,expectedVersion,signal}) resolves to the canonical {id,quantity,version} for that row. Use all returned canonical values. A normal rejection guarantees the write was not committed. A conflict rejects with error.latest containing the newer canonical row. A resolved or conflict row has the requested ID, a valid quantity and a current version. Different rows may finish in any order. The fixture may complete a promise after cancellation. There are no ambiguous committed-but-timed-out writes in this exercise.

Acceptance criteria

  • Increase and Decrease change quantity by one within 1..20. Show the proposed quantity immediately and Saving for that row.
  • Send the desired quantity and that row’s confirmed version. Allow at most one pending request per row; other rows stay usable.
  • Disable that row’s quantity controls while pending or awaiting an explicit error decision.
  • Success replaces that row with the canonical server quantity/version and clears its pending, error and intent state.
  • Normal failure restores that row’s confirmed pre-request quantity/version and shows Could not save quantity.
  • Conflict shows error.latest as current state and Quantity changed on the server.
  • Both failures retain Your change: N. Apply my change resends N with the now-current version; Keep current discards N without a request.
  • Completing or rolling back one row never changes another row’s success, pending state or error.
  • Disable Decrease at quantity 1 and Increase at quantity 20. Empty input shows No checkout items.
  • On unmount abort every pending request and ignore subsequent completions. Do not mutate initialLines.

Constraints

  • 0..100 checkout lines; ASCII IDs are 1..40 characters and titles 1..120 characters.
  • No HTTP server, persistence, authentication, payment action or distributed lock is required. The supplied API provides the atomic version check.
  • There is no automatic conflict overwrite or retry loop. Each retry needs the explicit Apply my change action.

Editable files

  • src/CheckoutApp.jsx — Repair optimistic state, row reconciliation and intent recovery.
  • src/helpers.js — Optional helpers for this implementation.
  • tests/candidate.test.js — Add 3 new behavioral regressions; do not duplicate the supplied smoke test.

What this task practices

Resolve Checkout Conflicts is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.