All practice tasks

Coding (Platform)

Consistent Reservation Flow

Vue + Fastify · Hard · Cross Layer Consistency

The Vue screen and Fastify service already run separately. Their integration contains transport and state regressions. Own both Vue lifecycle behavior and Fastify response semantics. A passing isolated unit test on either side is not enough.

Task

Deliver one working browser-to-service flow, not two disconnected implementations. 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. Make reservations atomic and idempotent within one service process, with deterministic concurrency and failure tests.

Contract

  • Browser — 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.
  • Browser — User action: The user presses Reserve on one project. One deliberate reservation is one intent; retrying it is not a new intent.
  • Browser — 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.
  • Browser — Timing guarantees: API operations may resolve or reject in any order, even after cancellation. The fixture controls completion order; no real network is used.
  • API — Request: POST /projects/:id/reservations; :id is the project being reserved. Send the body as JSON with Content-Type: application/json.
  • API — JSON body: quantity — seats requested; integer from 1 through 10. expectedVersion — project version last read by the caller; positive integer. requestId — identity of this reservation attempt; 1–40 lowercase letters, digits or hyphens. Example: {"quantity": 1, "expectedVersion": 3, "requestId": "reserve-42"}.
  • API — Authentication: Authorization: Bearer fixture-alpha identifies tenant alpha; fixture-bravo identifies tenant bravo. The supplied authentication helper resolves the tenant. A query/body field is not an identity source.
  • API — Request delivery and storage: The same request may arrive again after a timeout. Different requests may overlap. Repository operations from different requests may overlap, and a write may fail. Use the provided single-process exclusive boundary. No distributed storage is part of this task.
  • Connecting the two layers: web/src/api-client.js is the browser-to-HTTP adapter. api.list reads the HTTP response’s items array. api.reserve maps the HTTP receipt’s remaining field to the component’s seats field.

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 component unmount, cancel every pending operation and ignore later results.
  • Return HTTP 200 with {id, quantity, remaining, version}.
  • remaining is the seat count after subtracting quantity; version increases by exactly one.
  • Concurrent requests must not reserve more seats than exist.
  • The key is the authenticated tenant plus requestId.
  • Same key and same project, quantity and expected version: return the original receipt without changing stock again.
  • Check for that receipt before checking the project’s current version.
  • Same key with different reservation data: HTTP 409, code IDEMPOTENCY_CONFLICT.
  • Malformed body: HTTP 400, code INVALID_RESERVATION.
  • Missing or unknown bearer token: HTTP 401, code UNAUTHORIZED.
  • Missing, archived or another tenant’s project: HTTP 404, code NOT_FOUND.
  • Version changed: HTTP 409, code VERSION_CONFLICT.
  • Not enough seats: HTTP 409, code INSUFFICIENT_SEATS.
  • Repository write failed: HTTP 503, code RETRY_LATER.
  • Every error body is {code: "THE_CODE"}.
  • Do not consume seats, increment the version or save a successful receipt.
  • Retrying the same request must still be possible.
  • URL-encode search text; it must not become extra query parameters.
  • Reject failed HTTP responses with their status. Do not hide errors as an empty successful list.

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.
  • At most 10000 projects in the repository; reservation JSON body at most 16 KiB.
  • Use the supplied repository and authenticated tenant resolver. No external database, network service or production credential is needed.
  • The reservation guarantee is single-process only. Do not claim distributed or durable idempotency from an in-memory store.
  • All services run inside the test process on loopback. No external deployment, database or cloud account is required.

Editable files

  • web/src/ProjectApp.vue — Repair the component state, lifecycle and API coordination.
  • web/src/ProjectRows.vue — Provided row rendering; preserve identity, accessibility and button semantics.
  • web/src/helpers.js — Optional pure helpers; not a replacement for framework lifecycle handling.
  • web/tests/candidate.test.js — Add DOM-level regression tests using fixture(t), deferred() and assert.
  • server/src/app.js — Framework router/controller, middleware and error response integration.
  • server/src/service.js — Repair filtering/pagination or the reservation consistency boundary.
  • server/src/helpers.js — Optional helpers; import from service when needed.
  • server/tests/candidate.test.js — Add the required regression tests here using fixture(t), assert and node:test.
  • web/src/api-client.js — Repair URL encoding, error propagation and response DTO mapping.
  • integration/candidate.test.js — Add cross-layer regressions; reuse the local integration fixture.

What this task practices

Consistent Reservation Flow 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.