Preparing your design workspace

Loading the problem and your saved attempt…

Design a Capacity-Based Job Assignment Tracker

Assign jobs to workers without exceeding any worker's capacity, queue what does not fit, and keep job and worker state consistent as jobs finish, are cancelled, or workers go offline.

Design and implement an in-memory task tracker that assigns jobs to workers according to each worker's capacity.

For this exercise, assume the following product facts. An operator registers workers, each with a unique ID and a capacity: the largest total job size the worker may hold at once. The operator submits jobs, each with a unique ID and a positive size.

The tracker assigns a submitted job right away to a worker whose remaining capacity fits it; when several fit, it picks the worker with the most remaining capacity, and on a tie the smaller worker ID. The choice of worker must be replaceable by another policy later without changing the tracker.

When no worker fits, the job waits. When a job completes or is cancelled, its worker's capacity is freed and the waiting jobs are tried again in the order they were submitted; every waiting job that now fits is assigned, even if an earlier, larger job still has to wait.

A job larger than every registered worker's capacity is rejected at submission. A job is WAITING, ASSIGNED, DONE or CANCELLED; DONE and CANCELLED are final. Completing a job that is not ASSIGNED, or cancelling a DONE or CANCELLED job, is an invalid transition.

The operator can read a job's state and worker, and a worker's used capacity and jobs. Rule that must always hold: a worker's used capacity equals the sum of the sizes of its assigned jobs and never exceeds its capacity, and a job is held by at most one worker.

Everything runs in one process on one thread, and nothing has to survive a restart. Job priorities, deadlines, retries and worker skills are out of scope.

This practice version puts the most weight on the data model: produce the requirements, object model, method contracts and one walkthrough, then implement the core, then extend it in the follow-up.