Design System to Execute Test Binaries from User Machines on Worker Machines

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-07-08

Problem Statement

Design a system that allows users to upload test binaries (e.g., executables, test scripts, or automation suites) from their local machines, which will then be executed on a pool of worker machines managed by the system.


The system should handle:


•Job submission
•Queueing and scheduling
•Remote execution
•Result reporting
•Scalability across multiple workers


This system simulates how large-scale CI/CD or test execution platforms (like Jenkins, Bazel Remote Executors, or Nutanix Test Orchestrators) manage distributed workloads.


🧩 Context


In large engineering setups, test workloads need to be executed in distributed environments — user machines can’t handle heavy compute loads or consistent environments.


Your system should allow:


•Developers to upload a test binary.
•A scheduler to allocate an idle worker machine.
•The worker to download, execute, and return results/logs.
•The system to track job states (queued, running, completed, failed).


This is an LLD problem, so focus on class structure, components, and their interactions.


✅ Functional Requirements


1.User uploads a binary or test bundle for execution.
2.Scheduler assigns an available worker machine for execution.
3.Worker executes the test binary and returns output logs and result status.
4.System supports multiple concurrent jobs.
5.Support for job states — PENDING, RUNNING, COMPLETED, FAILED.
6.Allow users to query job status and fetch logs.
7.Handle failures — if a worker fails, the job should be retried or marked failed.


⚙️ Non-Functional Requirements


AspectDescription


Scalability

Should support hundreds of concurrent jobs.


Reliability

Ensure no job is lost; retry mechanism on failure.


Extensibility

Add new worker types or job priorities easily.


Maintainability

Use modular, SOLID class design.


Concurrency

Multiple workers can run jobs simultaneously.


🧱 Core Components / Classes


ComponentResponsibility


UserClient

Interface for users to submit test binaries and request status.


JobManager

Handles job lifecycle — creation, tracking, and state transitions.


JobQueue

Holds pending jobs waiting for workers.


WorkerManager

Tracks available worker machines and assigns jobs.


Worker

Executes assigned test binaries, reports back results.


Scheduler

Decides which job goes to which worker (based on load, availability).


ResultStore

Persists execution results and logs for retrieval.


NotificationService

Notifies users when jobs complete or fail.


🧾 Class Diagram (Text Representation)

1 2┌────────────────────────┐ 3│ UserClient │ 4│────────────────────────│ 5│ + submitJob(file): Job │ 6│ + getJobStatus(id): Status │ 7│ + getResult(id): Result │ 8└─────────────┬──────────┘ 9 │ 10 ▼ 11┌────────────────────────┐ 12│ JobManager │ 13│────────────────────────│ 14│ + createJob(file): Job │ 15│ + updateJobStatus(id, status): void │ 16│ + getJob(id): Job │ 17└─────────────┬──────────┘ 18 │ 19 ▼ 20┌────────────────────────┐ 21│ JobQueue │ 22│────────────────────────│ 23│ + enqueue(job): void │ 24│ + dequeue(): Job │ 25│ + isEmpty(): bool │ 26└─────────────┘ 27 28┌────────────────────────┐ 29│ Scheduler │ 30│────────────────────────│ 31│ + assignJob(job): void │ 32│ + pickWorker(): Worker │ 33└─────────────┬──────────┘ 34 │ 35 ▼ 36┌────────────────────────┐ 37│ Worker │ 38│────────────────────────│ 39│ + id: String │ 40│ + status: WorkerStatus │ 41│ + execute(job): Result │ 42└────────────────────────┘ 43 44┌────────────────────────┐ 45│ WorkerManager │ 46│────────────────────────│ 47│ + register(worker): void │ 48│ + getAvailableWorker(): Worker │ 49│ + markBusy(worker): void │ 50│ + markFree(worker): void │ 51└────────────────────────┘ 52 53┌────────────────────────┐ 54│ ResultStore │ 55│────────────────────────│ 56│ + saveResult(job, result): void │ 57│ + getResult(jobId): Result │ 58└────────────────────────┘


🔄 Workflow Example


1.User submits a test binary via UserClient.submitJob().
2.JobManager creates a Job with state PENDING and adds it to the JobQueue.
3.Scheduler continuously polls the queue and assigns jobs to idle workers from WorkerManager.
4.Worker downloads the binary, executes it, and streams logs to ResultStore.
5.On completion, Worker updates the job state to COMPLETED (or FAILED).
6.NotificationService informs the user of completion/failure.
7.User fetches results using UserClient.getResult(jobId).


🧩 Key Entities


EntityAttributesDescription


Job

id, filePath, status, assignedWorker, timestamp


Represents one test binary execution task.


Worker

id, status, capacity, ipAddress

Represents a machine that executes jobs.


Result

jobId, status, outputLogs, executionTime

Captures the execution result of a job.


🧠 Design Patterns Used


PatternPurpose


Observer Pattern

Notify users when job state changes.


Strategy Pattern

Allow different scheduling strategies (e.g., round-robin, least-loaded).


Singleton Pattern

For JobManager and WorkerManager to maintain consistent system state.


Command Pattern

Represent each job execution as a command object.


Factory Pattern

For creating worker or job instances dynamically.


⚙️ Example Scenario

1 2User uploads: test_suite_v2.tar.gz 3 4🟢 Step 1: Job Created 5Job ID: 1234 | Status: PENDING 6 7🟡 Step 2: Scheduler assigns worker 8Worker: worker-node-05 | Status: BUSY 9 10🟣 Step 3: Execution 11Worker downloads test_suite_v2.tar.gz 12Runs test binary -> Captures output logs 13Result: SUCCESS | Duration: 42s 14 15🔵 Step 4: User retrieves results 16Job ID: 1234 | Status: COMPLETED | Logs: test_suite_v2_output.log


💬 Discussion Points for Interview


•How do you handle worker crashes mid-job?
•How can you scale this for hundreds of concurrent users?
•How to design retry logic and job prioritization?
•Can jobs be canceled or paused?
•How to handle security (sandboxing user binaries)?


🧠 Possible Extensions


•Add priority queues (high vs low priority jobs).
•Support Docker-based sandbox execution.
•Add heartbeat mechanism for worker liveness tracking.
•Introduce REST APIs or message queues (RabbitMQ/Kafka) for coordination.
•Support execution time limits and resource quotas.


✅ Final Summary

Problem Statement:
Design a system to execute test binaries uploaded by users on a pool of worker machines. The system should manage job scheduling, worker allocation, execution tracking, and result reporting, ensuring scalability, fault tolerance, and ease of extension.


Solution

Comments