All practice tasks

Coding (Platform)

Shared query lifecycle

express + react · Hard · cache lifecycle

A browser and API disagree at the shared query lifecycle boundary. Several panels subscribe to the same query. The current cache aborts the shared request when any panel unmounts and commits a late response after the final subscriber has gone.

Task

Repair the shared browser-to-service contract. Reduce subscribe, unsubscribe, resolve and reject events into cache state with reference-counted ownership.

Contract

Input is {events}. subscribe/unsubscribe carry key and subscriber; resolve/reject carry key and requestId. Return entries keyed by query with subscribers, status, value, error and aborted request IDs.

Acceptance criteria

  • One pending request is shared per key.
  • Unsubscribing one consumer keeps work alive for remaining consumers.
  • The last unsubscribe aborts and invalidates the request.
  • Late settlements from invalidated requests are ignored.
  • Keep browser-visible state consistent with the canonical service result.

Constraints

  • Do not mutate caller-owned input.
  • Keep the supplied framework adapter and public contract unchanged.
  • Add candidate tests for at least one boundary not covered by the public cases.

Editable files

  • src/repair.js — Task-specific state or service boundary
  • tests/candidate.test.js — Candidate-authored regression

What this task practices

Shared query lifecycle 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 State Modeling, Regression Testing, Technical Reasoning. 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.