KatInterview

Design an Asynchronous Job Service for Batch File Operations

System DesignModel answer
MediumModel answerSystem Designapi-designasync-jobsdistributed-systems

Last updated

Design an HTTP API and backend system to process large batches of files asynchronously, handling long-running work, job tracking, and failures.

You're building a backend service for a cloud file storage platform that needs to run operations on user files—think thumbnail generation, optical character recognition, or content analysis.

Your task is to design the HTTP API and high-level system architecture.

Phase 1: Basic synchronous endpoint

Begin with a straightforward case:

  • A client sends a batch of file identifiers (IDs or paths belonging to the authenticated user)
  • Your service processes all of them and returns the complete results in one HTTP response
  • Assume each file takes less than a second to process, so the entire request completes well within normal timeout windows

Design a REST endpoint such as POST /processFiles that handles this scenario. Include:

  • How clients specify which files to operate on
  • The shape of the response: per-file outcomes, any output data, error details
  • Basic failure handling when individual files cannot be processed

Sketch the main backend components and request flow at a high level.

Phase 2: Supporting long-running batch jobs

Now make it realistic: each file may take seconds or minutes to process, and batches can be large. A blocking HTTP request will hit timeout limits and create a poor user experience.

Redesign the system to handle work asynchronously.

Updated requirements:

  • Clients submit a batch and receive an immediate response, even if processing will take many minutes
  • Clients can poll or query to learn:
    • Current job status (queued, running, done, failed)
    • Results for each file once available
  • The system must tolerate:
    • Server crashes and restarts without losing work
    • Duplicate submission attempts from clients (idempotency)
    • Scaling to handle many concurrent jobs

What to address

Provide a design covering:

  1. API contract

    • Endpoints for submitting a job, checking its status, and fetching results
    • High-level structure of requests and responses
  2. Core architecture

    • How you persist job state (outline the data model)
    • How processing work actually gets done (workers, task queues, etc.)
    • How the system scales horizontally
  3. Handling long-running operations

    • Decoupling submission from execution to avoid tying up connections
    • Ensuring clients can safely retry without creating duplicate jobs
    • Dealing with partial outcomes (some files succeed, others fail)
  4. Reliability and scale

    • Making sure jobs survive crashes and eventually complete or are marked failed
    • Strategies for idempotency and deduplication
    • Key performance bottlenecks and how you'd address them

You don't need to write production code—just explain the design clearly enough that an engineer could build it from your description.

Hints

Hint 1

Think about how to decouple the HTTP request lifecycle from the actual work duration—what pattern separates submission from execution?

Hint 2

Consider what makes a retry safe: how can you tell whether a request with the same parameters has already been accepted?

Hint 3

For partial failures, decide whether to fail the entire job or track per-file outcomes independently—which gives better visibility and recovery options?