All practice tasks

Coding (Platform)

Optimistic Seat Reservations

Dom · Hard · Optimistic Updates

A team lead uses the Projects page to reserve available places for teammates on several projects. Clicking Reserve immediately reduces that project’s displayed seat count while the API confirms the reservation. The current component restores an old copy of the entire list after a failed request, so a failure on Alpha API can erase a successful reservation on Beta Web; a retry can also be treated as a new reservation. The reservation API is supplied: repair the client’s per-project state and retry behavior without building another backend.

Task

Make reservations independent: if Alpha API fails while Beta Web succeeds, restore only Alpha’s row and keep Beta’s confirmed count; retrying Alpha must reuse its original request ID.

Contract

  • Starting data: initialRows is the supplied project list. Do not mutate it. id identifies a project; title is its visible name; archived hides it from the active list. seats is the available seat count; version identifies the last server version of that project.
  • User action: The user presses Reserve on one project. One deliberate reservation is one intent; retrying it is not a new intent.
  • Provided reservation API: api.reserve(id, {expectedVersion, requestId, signal}) returns a Promise of {id, seats, version}. makeRequestId() supplies a key for a new intent. An error may include latest, the server’s newer project values.
  • Timing guarantees: API operations may resolve or reject in any order, even after cancellation. The fixture controls completion order; no real network is used.

Acceptance criteria

  • Immediately subtract one displayed seat from the selected row.
  • Show Saving for that row. Disable Reserve while it is pending or has zero seats.
  • Keep other rows interactive.
  • Success: use the returned server values for that row and clear its pending/error state.
  • Failure: restore that row’s pre-attempt values, or use the newer server values supplied with the error.
  • On failure, show Reservation failed for that row and clear its pending state.
  • Never roll back another row’s successful reservation.
  • Retry a failed intent with the same key. Clear that intent after success.
  • At unmount(), cancel every pending operation and ignore later results.

Constraints

  • At most 200 rows; IDs are unique ASCII strings and seats are non-negative integers. Input props must not be mutated.
  • Keep the Search projects label, data-id row identity and accessible status messages. Preserve per-row button semantics; changing search behavior is not part of this reservation task.
  • Use the injected fake API, not hard-coded results. Abort obsolete work and guard against promises settling after abort.
  • No outbound network, paid API or browser permission is needed. New files are not submitted by the embedded widget.

Editable files

  • src/ProjectApp.js — Repair the component state, lifecycle and API coordination.
  • src/ProjectRows.js — Provided row rendering; preserve identity, accessibility and button semantics.
  • src/helpers.js — Optional pure helpers; not a replacement for framework lifecycle handling.
  • tests/candidate.test.js — Add DOM-level regression tests using fixture(t), deferred() and assert.

What this task practices

Optimistic Seat Reservations 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.