All practice tasks

Coding (Platform)

Reference-counted service cache

nestjs · Hard · cache lifecycle

A production API needs a reference-counted service cache repair at its service 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

Implement the reference-counted service cache contract used by the supplied HTTP adapter. 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.
  • Return a deterministic JSON-serializable result for the HTTP adapter.

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

Reference-counted service cache 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.