Skip to content

A job-execution platform: submit, isolate and observe

10 min reading

A design for accepting jobs, controlling resources and recording outcomes

Page details

System Design · Compose complete systems

10 min reading · 25 min with practice

Sources

Published · Last edited:

Prerequisite: A crawler under hostile and changing inputs. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Northwind teams submit document conversions and scheduled reports. Dev places a queue in front of containers. Maya asks for a stable receipt even when dispatch is interrupted; Priya asks which data and services a running job may access.

Dev: “The queue can distribute the attempts.”

Maya: “Which durable fact makes the platform responsible for finishing this particular job?”

Connect submission identity, accepted lifecycle, admission, isolation and results. Start with approved job types and immutable inputs; arbitrary customer code remains a different security product. This is a core System Design case with no model or agent prerequisite.

Which durable fact makes this job accepted?

A submission contract identifies the tenant, job type, immutable input reference, selected limits and caller intention. Repeating an uncertain submission with the same intention returns the existing job identity. Reusing that identity with incompatible input is rejected. This prevents a lost receipt from silently creating another report or conversion.

The authoritative job record is durable before the service acknowledges acceptance. Record a recoverable scheduling obligation in the same transactional boundary where possible. A queue message can then be published and retried independently. Without that connection, a crash can leave an accepted job permanently absent from the worker queue.

Acceptance is not a reservation of immediate compute. The receipt states whether the job is admitted to a bounded queue and how its deadline and cancellation work. Reject before acceptance when the tenant’s retained-work or resource budget is exhausted. Returning an optimistic receipt and later forgetting the job violates the very contract the platform exists to provide.

Separate a logical job from each attempt

The scheduler assigns an attempt identity and ownership generation through a conditional transition. A worker claims that attempt, obtains narrowly scoped input access and runs the approved job type. Heartbeats are observations supporting timeout decisions; they do not prove that a silent worker has stopped.

Store attempt outcomes separately from the logical job state. A failed attempt may leave the job eligible for retry, while a terminal input error may end it. The final result reference is published only by a currently authorized transition. Logs and progress events help diagnosis but are not the sole source of accepted completion.

Use immutable result objects named by job and attempt. The platform can retain an unaccepted attempt’s object temporarily without exposing it as the authoritative result. A conditional result pointer connects the accepted job outcome to exactly one complete artifact. This avoids using overwrite arrival order as the winner rule.

Submission, execution and published result have different authorityA submission becomes a durable accepted job. A bounded authorized attempt executes it. An immutable artifact becomes visible only through the guarded logical-job result transition.Tenant + intentionDurable accepted jobScheduling obligationAdmission + attemptBounded workerNarrow input accessImmutable artifactGuarded result pointerOutcome + audit
Submission, execution and published result have different authority

Trace durable submission into a bounded worker capability

Hypothetical scenario. Submit operation K creates job J with immutable input and a durable scheduling obligation. A broker notification wakes the scheduler but is not the sole record that J exists. Scheduler restart rebuilds pending work from durable state rather than assuming every accepted job still has a queue message.

Trace durable submission into a bounded worker capability — selected design evidence
RecordFieldsAuthority
Job JK, tenant, input digest, desired stateSubmission owner
Attempt AJ, generation, worker, leaseScheduler / job state
Resource claimworker, CPU/memory, generationAdmission authority
Result candidateJ, attempt, input digest, objectConditional result acceptance
The job authority accepts a result only after checking job, attempt and input identity.The job authority accepts a result only after checking job, attempt and input identity. Submitter to Job authority: 1 · K + immutable input; Job authority to Scheduler: 2 · durable pending J; Scheduler to Worker: 3 · scoped admitted attempt; Worker to Job authority: 4 · candidate result.SubmitterJob authoritySchedulerWorker1 · K + immutable input2 · durable pending J3 · scoped admitted attempt4 · candidate result
The job authority accepts a result only after checking job, attempt and input identity. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

The scheduler chooses a worker compatible with the job's declared CPU, memory and capability requirements. A task queue distributes items; resource scheduling additionally decides whether a particular worker can admit the item without violating tenant or machine limits. Keep resource claims recoverable and release them through a guarded lifecycle.

A worker receives a scoped attempt identity, input reference and authority token, not unrestricted platform credentials. It uploads an immutable candidate result; the job authority accepts it only for the current attempt generation and required input. Cancellation changes which transitions remain legal, but a running process may continue until enforcement reaches it. State which effects can be stopped and which require protected remote identities.

Estimate useful capacity in worker time

Hypothetical worked example. Select twelve worker slots and a mean attempt occupancy of thirty seconds for one homogeneous job class. Ignoring scheduling overhead and failures, the attempt capacity is 12 ÷ 30 = 0.4 attempts per second, or 0.4 × 60 = 24 attempts per minute. This is a planning subtotal, not a measured service guarantee.

Select eighteen new logical jobs per minute and one attempt per job initially. Useful spare capacity is 24 − 18 = 6 jobs per minute. A backlog of one hundred twenty jobs would drain in 120 ÷ 6 = 20 minutes if arrivals and successful service remain constant. Increasing submission throughput does not increase those worker slots.

Now select an average of 1.2 attempts per successful logical job under retries. The same twenty-four attempts per minute support 24 ÷ 1.2 = 20 successful jobs per minute. Spare useful capacity becomes 20 − 18 = 2 jobs per minute, and the backlog drain estimate becomes 120 ÷ 2 = 60 minutes. Attempt occupancy and retry mix can differ in reality; these deliberately fixed assumptions expose the unit change.

Resource limits need an actual trust boundary

For the approved-type baseline, workers receive read access to declared inputs and write access only to their attempt output prefix. The control plane keeps scheduler credentials and tenant policy outside that environment. Apply CPU, memory, storage, network and wall-clock bounds; a memory cap does not bound outbound requests or retained logs.

Containers are a packaging and resource-management mechanism. Their suitability as isolation depends on the threat model, runtime and host boundary. Running hostile code may require a stronger sandbox and a separate worker fleet. Do not infer safety from a container icon while mounting broad credentials or permitting privileged host access.

Admission must also account for fairness. A tenant with a large backlog should not consume every scarce slot indefinitely. Separate classes or weighted scheduling can help, but enforce both retained-work limits and active-resource limits. Otherwise a polite active limit can coexist with an unbounded tenant queue.

In the wild: a Job controller retries execution

Kubernetes documents Job completion and replacement behavior. Inspect its failure and retry semantics before using it as the execution substrate. Controller-managed completion does not establish exactly-once business effects; the application still needs stable identities and a guarded result boundary.

The platform can translate an accepted job into a Kubernetes Job while retaining its own tenant, input and result contract. Avoid exposing raw infrastructure state as the complete user lifecycle. A pod may disappear while the durable job remains unresolved, and a completed process can still fail result publication.

A receipt survives but its message does not

Hypothetical failure scenario. The submission service writes a job record, acknowledges the caller, then crashes before sending its queue message. A dashboard reports the job as queued forever. The worker pool is idle because no worker knows the accepted obligation exists.

Recover from a durable scheduling obligation and reconcile accepted jobs that lack progress. Publishing twice is tolerable when delivery and attempt claims are idempotent. Publishing zero times indefinitely is not. Reconciliation needs a bounded scan and explicit age thresholds, not an operator’s memory of which receipts looked suspicious.

Choose the smallest platform that preserves the contract

A shared platform is useful when several teams need the same admission, isolation and lifecycle guarantees. For a single trusted report, an existing scheduler with durable state may be enough. The extra platform boundary is justified by common obligations, not by an assumption that every background task needs a custom control plane.

Measure accepted jobs, waiting age by class, attempt occupancy, useful completions, unresolved outcomes and artifact publication failures. Avoid reporting queue depth alone as health: a small queue can coexist with a stuck tenant, while a planned batch can create a large healthy queue. The next page removes a worker at an ambiguous moment and asks which authority remains valid.

Challenge the proposed mechanism

Job state survives missing broker notifications and worker replacement.Job state survives missing broker notifications and worker replacement. Submitted J to Admitted attempt: resource + authority grant; Admitted attempt to Accepted result: current generation + input match.Submitted JAdmitted attemptAccepted resultresource + authority grantcurrent generation + input match
Job state survives missing broker notifications and worker replacement. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

The submit reply was sent but broker publication failed. How does the platform recover J?

Reveal the design reasoning

The committed job and dispatch obligation remain authoritative. Rebuild notifications from that state, preserving K and J. Do not ask the client to submit a new business intention or grant the replacement worker broader capability.

Decision and reconsideration: Use durable submission, explicit resource admission and conditional results. Separate task delivery from scheduling authority.

Check the design against changed conditions

  1. The queue publish failed after a durable receipt. May the job be forgotten?

    Reason through the consequence

    No. Recover the scheduling obligation and reconcile accepted work. The receipt bound the platform to a lifecycle even though immediate execution was not promised.

  2. Retries increase to 1.2 attempts per successful job. Is spare capacity still six jobs per minute?

    Reason through the consequence

    Under the selected fixed occupancy, useful capacity becomes twenty jobs per minute, leaving two above eighteen arrivals. The backlog estimate increases to sixty minutes.

  3. The process exited successfully but its artifact is incomplete. Is the logical job complete?

    Reason through the consequence

    No under the selected contract. Publish only a complete immutable artifact through the guarded result transition; process exit alone is insufficient evidence.

A durable baseline can still encounter a worker that disappears after producing output. Page 60 keeps the same job identity and capacity inputs while a replacement and the old process compete to complete the result.

Northwind decision log

Acknowledge a durable job and recoverable scheduling obligation.
Bound each attempt and publish results through current authority.
Next, recover worker loss without repeating uncontrolled effects.

Go deeper: Durable submission and bounded ownership