Reviewing Correctness in Distributed & Concurrent Code

The hardest bugs to catch in review are the ones that only appear on a retry, a race, or a partial failure.

This is the deepest technical question in the code-review track, and for an ads-events-infra engineer it's the one where you should sound most fluent. Distributed and concurrent code is correct on the happy path and subtly wrong the moment a message is redelivered, two threads interleave, a node dies mid-write, or a clock skews. None of those show up in a single-threaded unit test. The interviewer wants to hear that when you review ingestion, execution, or any multi-node path, you're running a mental model of “what happens if this runs twice, out of order, or half-fails” — and that you know the concrete failure modes by name.

Flow of reviewing distributed and concurrent correctness: idempotency, delivery model, ordering, races and locks, visibility, partial failure, deadlines, consistency
The distributed-correctness checklist: idempotency, the delivery model, ordering assumptions, races and locking, memory visibility, partial failure, deadline/retry propagation, and consistency — assume every step can happen twice or fail halfway.

What this question is really testing

Whether you have internalized the fallacies of distributed computing and the concurrency memory model well enough to spot violations in someone else's diff. The tell is that you don't assume reliable, ordered, exactly-once delivery or a single-threaded world — you assume the opposite and ask the code to prove it's safe. This is also where allocation and concurrency in core execution/ingestion paths matter: a data race or a lock held across I/O in the hot path is both a correctness bug and a performance one.

How to answer What the interviewer is looking for

The most common catch — a non-idempotent, non-atomic counter update on an at-least-once stream:

# WRONG: redelivery double-counts; read-modify-write races across consumers
def on_click(event):
    count = store.get(event.ad_id)        # two consumers read the same value
    store.put(event.ad_id, count + 1)     # lost update + double count on retry

# RIGHT: dedup by event id, then an atomic op that's safe to replay
def on_click(event):
    if not store.mark_seen(event.event_id):  # idempotency key, first-writer-wins
        return                               # duplicate delivery -> no-op
    store.atomic_incr(event.ad_id, 1)        # atomic, no lost update

Common follow-ups

How do you actually verify concurrency correctness in review?

How to answer

When is eventual consistency acceptable?

How to answer

How do you review a change to a locking scheme?

How to answer

What's your stance on wall-clock time in distributed code?

How to answer
Where to get your data (Meta)