KatInterview

Distributed Transposition of a Terabyte-Scale Dense Matrix

System DesignModel answer
HardModel answerSystem Designdistributed-systemsobject-storagefault-tolerance

Last updated

Design a fault-tolerant distributed pipeline that transposes a multi-terabyte float matrix using tiled partitioning, idempotent workers, and verifiable completion tracking.

Context

Large-scale data platforms in areas like sensor fusion and computer vision routinely produce enormous dense matrices — feature covariance tables, embedding similarity grids, and similar structures. Suppose your platform generates float32 matrices of size 1,000,000 × 1,000,000 on a regular schedule (roughly 4 TB of raw data). No single machine has enough memory or local disk to hold this, so the transposition job must run across a fleet of short-lived workers backed by cloud object storage (assume S3-compatible).

Your task is to design the end-to-end distributed batch system that performs this transpose correctly, survives worker failures mid-job, and can prove it finished cleanly.

What You Need to Design

Functional Goals

  • Block decomposition: Split the source matrix into square tiles of configurable size B × B. Each tile is an independent unit of work.
  • Distributed execution: Assign tile (row r, col c) to a worker that reads it, transposes it in local memory, and writes the result to output position (col c, row r).
  • Safe retries: If a worker crashes or times out, another worker must be able to redo the same tile without corrupting the output or creating duplicate writes.
  • Completion guarantee: The system must detect with certainty when every tile has been successfully written, and expose a way to verify correctness.

Non-Functional Goals

  • Scale: The design must extend to matrices with up to 10¹² elements (tens of TB).
  • Fault tolerance: Spot or preemptible nodes can be terminated mid-task; the job must continue without restarting from scratch.
  • I/O efficiency: Avoid unnecessary re-reads or re-writes. Total bytes moved should stay close to the theoretical minimum of 2× the matrix size (one full read, one full write).

What Your Answer Should Cover

  1. Coordinator and worker architecture — how work is scheduled, leased, and tracked.
  2. Storage layout — how input and output tiles are named and formatted in object storage to enable efficient random access.
  3. Idempotence and fault recovery — how the system handles worker timeouts, duplicate writes, zombie workers, and coordinator restarts.
  4. Completion tracking and integrity verification — strategies for confirming every tile is present and correct.
  5. Tile size trade-offs — how choosing B affects throughput, scheduling overhead, memory pressure, and retry cost.

Hints

Hint 1

Start with concrete numbers: how many tiles exist for a reasonable value of B, how much data does each worker touch per task, and what sets the ceiling on aggregate throughput? These figures should drive every architectural decision that follows.

Hint 2

Think about what makes a tile write safe to retry. If the output of transposing tile (r, c) is always the same bytes written to the same key, what does that mean for a zombie worker that writes after its lease expires?

Hint 3

Completion tracking and integrity are separate concerns. A bitmap that counts DONE tasks tells you the job finished; a per-tile checksum stored at commit time tells you the output is correct. What is a cheap way to verify transpose correctness without re-reading all 4 TB?