Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Teams increasingly try to coordinate work across many processes with tools that resemble in-process synchronizers, such as distributed latches and barriers built on Redis or ZooKeeper. What long-term guidance would you give about coordinating work across processes?

In-process synchronizers work because threads share memory and do not vanish silently; across processes, nodes crash, pause and lose messages, so a distributed latch or barrier needs leases, timeouts and rules for members that disappear, and those are easy to get wrong. My guidance is to design work so it does not need coordination (partition it, make steps idempotent, let each worker progress alone), to use a proven workflow or orchestration system when coordination is truly needed, and to make failure behaviour explicit and tested either way.

Why this question is asked

A CountDownLatch on Redis or a barrier on ZooKeeper is attractive because the code reads exactly like the in-process version that engineers already know. That familiarity is the danger: it hides the fact that the guarantees are completely different. Interviewers at this level want to hear whether we can explain why, and whether we can steer many teams toward designs that survive real failures. In this answer, we will recap what in-process synchronizers rely on, look at what breaks when the same idea spans processes, walk through an example, and then lay out the guidance: avoid coordination by design, use proven systems when it is needed, and make failure behaviour explicit.

1What In-Process Synchronizers Quietly Rely On

A CountDownLatch inside one JVM depends on three things that we rarely say out loud. First, shared memory: every thread sees the same counter, and the memory model guarantees that a countDown() happens-before the await() that it releases. Second, threads do not disappear silently: if a thread dies with an exception, the JVM knows, and we can catch it in a finally block and still count down. Third, there is no partial failure: either the whole process is running or none of it is.

Across processes, all three assumptions break. The counter lives in Redis or ZooKeeper and is reached over a network that can delay or drop messages. A member can crash, be killed by the scheduler, or pause for twenty seconds in garbage collection and then wake up believing it still holds a role it lost long ago. And some members can fail while others keep running.

2What a Distributed Latch Must Handle

Take a simple distributed latch: ten workers each process a shard of a nightly job, and a final step waits until all ten have called countDown on a Redis counter. Now consider worker 7 crashing after it finished half of its shard. Nobody ever decrements the counter, so the final step waits forever, exactly like the startup latch problem, but now across machines.

To fix that, the latch needs to know that worker 7 is gone. That means a lease: each member holds a key with a time to live and must renew it, and if the lease expires, the member is considered dead. ZooKeeper's ephemeral nodes do this with sessions. But leases bring their own problems. A worker that pauses longer than its lease is declared dead, its shard is given to someone else, and then it wakes up and writes its results anyway. Preventing that needs fencing tokens: a number that increases each time the shard is reassigned, checked by the storage that receives the writes, so the stale worker's writes are rejected.

So a correct distributed latch is a small distributed system: membership, leases, timeouts, fencing and retries. Each piece is subtle, and a home-grown version is usually missing at least one of them. Curator's recipes for ZooKeeper and Redisson's objects for Redis implement some of this, but their exact semantics under network partitions and failover need careful reading, and Redis replication in particular is asynchronous, so a failover can lose recent writes.

Same name, different guarantees
ConcernIn one JVMAcross processes
Shared stateone counter in memorya remote key, reached over a network
Member diesknown at once, finally still runsunknown until a lease expires
Pausesa paused thread still holds its placea paused node may lose its lease, then wake up
Stale writersimpossibleneed fencing tokens
Partial failurethe whole process fails togethersome members fail, others continue
The API looks the same; the failure model does not.

3Prefer Designs That Do Not Need Coordination

The best distributed barrier is the one we never build. Most coordination exists because work was split in a way that makes steps depend on each other's timing. If we partition the work so each worker owns a disjoint piece, such as Kafka partitions assigned to consumers or date ranges assigned to batch steps, each worker can progress independently and nobody needs to wait for anybody.

Idempotency is the other half. If every step can be safely repeated, for example by writing results with a deterministic key and an upsert, then a crashed worker's piece can simply be retried by another worker without asking whether the first one finished. The final step no longer waits on a counter; it checks durable state, such as all ten shard result rows exist for tonight's date, and runs when that is true. That check can be repeated as often as we like, so a missed signal is harmless.

Notice what changed: we replaced a signal that must arrive with a fact that can be read. Signals get lost in distributed systems; facts in a durable store do not.

4When Coordination Is Required, Use a Proven System

Some processes genuinely need ordering across steps: a payment that must reserve, charge and then confirm, or a data pipeline whose stages depend on each other. For those, I would point teams to systems built for exactly this, such as a workflow engine like Temporal or a managed step-function service, Spring Batch's partitioning with a job repository for batch work, or the database's own locks and transactions when everything already shares a database. These tools have already solved leases, retries, timeouts and visibility, and they have been tested under failures that a team's custom primitive will meet for the first time in production.

The decision process I would recommend is short, and the order matters: it asks first whether the coordination can be removed.

Step throughChoosing how to coordinate work across processes
  1. Can the work be partitioned so workers are independent?for example by key, shard or date range
    YesPartition it; no coordination neededNoContinue
  2. Can each step be made idempotent and checked from durable state?results written with deterministic keys
    YesRetry freely; check facts, not signalsNoContinue
  3. Does everything already share one database?
    YesUse its transactions or row locksNoContinue
  4. Use a workflow or orchestration systemleases, retries and timeouts are built in
  5. Write down and test the failure behaviourmember crash, pause, partition, duplicate

5 steps in order. Play them, or step through them one at a time.

5Make Failure Behaviour Explicit and Tested

Whatever design a team chooses, I would ask them to answer a fixed set of questions in the design document: what happens when a member crashes in the middle, when it pauses longer than its lease, when the coordinator itself is unavailable, and when a message is delivered twice. Each answer should be a behaviour, such as the shard is retried after 60 seconds and the stale writer's results are rejected by the fencing check, not a hope.

Then those answers become tests. Killing a worker mid-shard in an integration test, or pausing a container, is cheap compared with discovering the behaviour during a real incident. Over the long term, this is what keeps the guidance alive: a design that cannot say what happens when a member disappears is not finished, no matter how familiar its API looks.

6Follow-up questions

Isn't a Redis lock with a TTL good enough for most cases?

It is good enough when the lock is an optimisation, such as avoiding two workers doing the same cheap job, because a rare duplicate is harmless. It is not good enough when correctness depends on mutual exclusion, because a paused holder can outlive its TTL and a Redis failover can lose the lock. In that case we need fencing on the protected resource, or a different design.

How do you get teams to stop building custom primitives?

By making the better path easier. A platform team can offer a supported workflow service, examples of partitioned and idempotent jobs, and a review checklist that asks the failure questions. When teams see that the questions take ten minutes to answer for a workflow engine and days for a custom barrier, most choose the engine.

What is a fencing token?

It is a number that increases every time ownership of a resource changes. The new owner gets a larger number, and the resource, such as a storage service, rejects any write carrying a number smaller than the largest it has seen. That way a stale owner that wakes up after a pause cannot overwrite the new owner's work.

7Conclusion

In this answer, we saw that in-process synchronizers depend on shared memory, threads that do not vanish silently and all-or-nothing failure, and that none of these holds across processes. A distributed latch or barrier therefore needs leases, timeouts, membership and fencing, which are easy to get wrong. The long-term guidance is to avoid coordination by partitioning work and making steps idempotent so workers check durable facts instead of waiting for signals, to use proven workflow or orchestration systems when coordination is required, and to write down and test what happens when members crash, pause or repeat.

What to say in the interviewAbout 80 seconds aloud

Open with

My starting point is that in-process synchronizers rely on things we get for free in one JVM: shared memory with happens-before guarantees, threads that can't disappear without us knowing, and all-or-nothing failure.

Then, if they want more

Across processes, none of that holds. Nodes crash, pause in GC, get partitioned, and messages arrive late or twice. So a distributed latch needs membership, leases, timeouts and fencing tokens so a paused node that wakes up can't overwrite someone else's work, and teams usually get at least one of those wrong.

My guidance would be, first, design the coordination away. Partition the work so each worker owns a disjoint piece, make every step idempotent, and have later steps check durable facts, like all ten shard results exist for tonight, instead of waiting for a counter to hit zero. A lost signal then doesn't matter.

Second, when ordering across steps is truly required, use a proven workflow or orchestration system, or the database's transactions if everything shares one database, rather than a custom primitive on Redis or ZooKeeper. And third, every design document must say what happens when a member crashes, pauses past its lease, or repeats work, and those answers become tests.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Teams increasingly try to coordinate work across many processes with tools that resemble...": https://scrivio-interview-library.netlify.app/java/synchronizers/c0a5fbc5e2/