KatInterview

Async API for Large-Scale Directory Traversal

System DesignModel answer
MediumModel answerSystem Designasync-jobsdistributed-systemsscalability

Last updated

Build a non-blocking API and worker system to crawl millions of files across cloud storage accounts with progress tracking and fault tolerance.

Problem Statement

You need to build a backend system that traverses the directory structure of cloud storage accounts containing millions of files. The system must expose an HTTP API where clients can start a traversal job, then poll for its status and retrieve discovered file metadata incrementally.

Requirements

Functional:

  • Expose an endpoint to initiate a traversal job, returning a job identifier
  • Provide an endpoint to query job status (queued, running, done, error) and retrieve partial results
  • Support traversals over accounts containing up to 10 million files
  • Return file metadata (path, size, modified timestamp, hash) without downloading content

Non-Functional:

  • Handle thousands of simultaneous traversal jobs
  • Survive worker crashes without losing progress or restarting from scratch
  • Maximize throughput by parallelizing directory enumeration across multiple workers
  • Respect strict per-account rate limits imposed by the storage provider (typically 10–20 req/sec)

Constraints:

  • The cloud storage API enforces per-account and global quotas
  • Directory trees may contain symbolic links that create cycles
  • Some directories may be deeply nested or contain tens of thousands of entries requiring pagination

What to Deliver

  1. Architecture overview: Identify the main components and how they communicate
  2. API specification: Define the HTTP endpoints, request/response shapes, and status codes
  3. Job orchestration strategy: Explain how tasks are distributed, tracked, and completed
  4. Rate limit and failure handling: Describe your approach to quota enforcement, retries, and crash recovery

Hints

Hint 1

Think about why blocking HTTP requests won't work for multi-hour operations—where should the actual traversal happen?

Hint 2

Consider representing each directory as an independent unit of work so progress survives crashes and parallelizes naturally

Hint 3

Use stable directory identifiers (not paths) to detect cycles, and maintain a shared visited set across all workers