skip to content

When a runtime starts a second copy of a unit running far behind its peers, what does that buy and what does it cost?

level: middleimportance: should knowfreq 46%

answer

  1. second copy, first one wins
  2. machine time bought, author time saved
  3. useless against a genuinely heavy unit
  4. needs units that actually finish
  5. beside a live unit, not after a failure

basics

~20 s

A duplicate attempt starts a second copy of a lagging unit on another machine and keeps whichever copy finishes first, discarding the other. It buys back machine-caused slowness, and it costs a second machine's time plus a second read of the same input.

solid answer

~50 s

The mechanism is a **duplicate attempt**: the runtime notices a unit running far behind the other units of the same step, starts a second copy of it elsewhere, and takes whichever copy finishes first. Note the distinction that trips people up - a duplicate attempt runs alongside a unit that has *not* failed, while a retry replaces one that already has. It is a trade of machine time for wall-clock time, and it is the one remedy for a straggler that costs the author nothing: no rewrite, no re-reasoning about correctness. It buys nothing at all against a unit that is slow because it holds far more records, because the copy reads the same records and takes the same hour. Where it is offered varies: it needs units that finish and comparable peers to measure against, so a job whose input never ends gets little or none of it.

go deeper

for a junior

Know the shape: the runtime can run a second copy of a lagging unit on another machine and use whichever finishes first, throwing the other away.

for a middle

Explain why it rescues a unit slowed by its machine and does nothing for one holding far more records, and name the cost: a second machine's time and a second read of the same input.

for a senior

Demonstrate that you know when to switch it off - a unit that touches an outside system - and that a job whose input never ends has no finished peers to measure lag against.

for a principal

Argue the economics: duplicated work is machine spend that saves author spend, which is the right trade on a cluster with headroom and the wrong one when the cluster is already the bottleneck.

## What a duplicate attempt is A **duplicate attempt** is the runtime starting a second copy of a unit that is running far behind its peers, on a different machine, and keeping whichever copy finishes first while discarding the other's result. The original is not cancelled when the copy starts; it may still win. One piece of vocabulary must be nailed down before anything else, because mixing it up silently moves the discussion into two other subjects: **a duplicate attempt starts a second copy of a unit that is still running; a retry starts a replacement for one that has already failed.** The first is a remedy for slowness and is what this item is about. The second is about recovery, and a rerun of a whole scheduled job is a third thing again. ## Why it works against a machine and not against data The mechanism rests on one assumption: that the same input, processed by the same code on a *healthy* machine, will finish sooner. That assumption holds exactly when the cause of the lag is the machine. - **Against a straggler** - a unit slowed by a failing disk, a noisy neighbour on the host, or a cold start - the copy runs at normal speed and finishes long before the limping original. You paid one machine-hour to recover most of an hour of wall clock. - **Against a unit holding an uneven share of records** - data skew, an uneven number of records per piece - the copy reads the same forty times the records and takes about the same forty times as long. You paid a second machine for nothing and the step finishes no earlier. This is the whole reason the previous diagnosis matters. The remedy is chosen by cause, and duplicating work is the remedy for precisely one of the two causes. ## What it costs 1. **A second machine's time**, for as long as both copies run. On a busy shared cluster that capacity was not free; it was taken from other queued work. 2. **A second read of the same input**, which on remote storage means real bytes over the network and, where the platform charges per request or per byte scanned, real money. 3. **A small amount of duplicated downstream pressure** while both copies produce output that is buffered or written locally, only one of which will be used. Against that, the cost it does *not* impose is the author's: nobody rewrites the job, nobody re-argues that the result is still correct. That asymmetry is why runtimes that offer the mechanism tend to have it on for ordinary work and off for the unusual cases. ## Where the mechanism is offered, and where it cannot be This varies across engines far more than people expect, and stating it as a universal is the classic error. For the mechanism to make sense at all, four things must be true: - **Units finish.** There has to be an end to a unit for one copy to beat another to it. - **There is a comparable population.** "Far behind" only means something measured against peers in the same step, so the runtime needs enough finished or progressing peers to form a sensible middle. - **Only one copy's output enters the result.** The runtime must be able to take one output and throw the other away without the rest of the job noticing. - **Repeating the work has no consequences outside the dataflow.** The moment a unit's function touches an outside system, discarding a copy's records does not discard what it did out there. A **continuous job over an endless input** - a job whose input never ends, so no step ever finishes - fails the first two outright, which is why this family of remedy is largely a finite-job mechanism. Engines also differ in what they measure to decide a unit is behind (elapsed time against a middle value, or fraction of input processed), how long they wait before acting, whether the mechanism can be turned off for one step rather than the whole job, and whether the losing copy is actively cancelled or merely ignored. Treat all of that as "designs differ"; the concept an interviewer is testing is the trade itself. ## The judgment an interviewer is listening for The strong answer says three things in order: this is a cure for machine-caused slowness only; it pays machine time to buy wall-clock time, which is usually a good trade on a cluster with spare capacity and a bad one on a saturated one; and it is unsafe for any unit whose work is visible outside the job. The weak answer treats it as a general fix for slow tasks, which quietly promises that the runtime will rescue a badly distributed key - it will not.

  • How does a runtime decide that one unit is far enough behind to be worth duplicating?
    By comparing a running unit against the peers of the same step - typically its elapsed time or its progress against a middle value drawn from units that have finished or are further along - and only once enough peers exist for that middle value to mean anything. The threshold, the measure and the waiting period differ between designs, which is why nobody should quote a number.
  • Why not keep both copies' output and merge them?
    Because both copies computed the same piece from the same input. Merging would put every one of those records into the result twice and corrupt every count and sum downstream. The runtime therefore lets exactly one copy's output become part of the step's result and drops the other's entirely.
  • Is it worth duplicating units on a cluster that is already fully booked?
    Usually not. The second copy takes capacity from work that is queued, so you buy wall-clock time on one job by lengthening others. Duplicated work pays best when there is headroom or when the job in question has a deadline the rest do not.

Dispatching a second courier with a copy of the same parcel and taking whichever arrives first. It is cheap insurance when one van is stuck in traffic, and completely pointless when the parcel itself weighs a tonne - the second van has the same tonne to carry.

saying these in an interview costs you the question

  • Treats a duplicate copy as a general cure for any slow unit
  • Confuses it with retrying a unit that has already failed
  • Thinks both copies' outputs are merged so no work is wasted
  • Assumes every runtime offers the mechanism, including endless-input jobs
  • Says it is free because the capacity was idle anyway