The interview problem
Design a coordination service that gives one worker ownership of a resource at a time. Workers can pause for minutes, lose connectivity and retry writes. Ownership should transfer after failures, while a resumed stale worker must not overwrite its successor's work. Explain the responsibilities of both the lease service and the protected storage system.
Original system-design practice, not a reported interview. Timing and scale examples are hypothetical. Primary documentation retrieved September 27, 2026.
1. Start with the paused-worker counterexample
Worker A acquires a 30-second lease with ownership generation 41. It reads a resource, then pauses for 45 seconds. The service expires the lease and grants generation 42 to B. B writes new state. A resumes and sends a write based on its old read. Without enforcement at the resource, both workers can have acted as owner even if the lease service never recorded two active owners simultaneously.
Checking the lease immediately before a write is insufficient: A can pause between checking and writing. A heartbeat callback that tells the process to stop is useful for efficiency, but cannot recall an already delayed network request. The correctness boundary must include the place where the mutation takes effect.
2. Build a consistent ownership authority
Use a consensus-backed metadata service with resource name, owner session, lease identity and monotonically increasing fencing token. Acquisition atomically grants ownership only when the prior lease is absent or expired according to the authority's rules. Renewal and release identify the exact session and lease, so an old release request cannot delete a successor's ownership.
Expose acquire(resource, request ID, deadline), renew(lease ID) and release(lease ID). A timed-out acquire has an uncertain outcome: query or retry the same logical acquisition instead of starting unrelated ownership attempts without cleaning up the first. Define whether repeated acquisition by one session is idempotent; do not accidentally promise general reentrant-lock semantics.
Authenticate callers, namespace resources by tenant and authorize acquisition. A fencing token is an ordering mechanism, not a secret granting arbitrary access. Persist generation allocation so restart does not reuse an older value. Disaster recovery of the authority must preserve ordering relative to every protected resource; restoring a stale counter can make future writes fail or destroy the intended safety contract.
3. Enforce tokens atomically at the resource
For each resource, storage retains the highest accepted fencing token. In the same transaction as the mutation, reject a token lower than that value; otherwise update the high-water mark and apply the write. When B's generation 42 has been accepted, A's later generation 41 write is rejected regardless of A's local belief about its lease.
A new owner should first install its token at the protected resource and receive acknowledgment before reading state for new work. This establishes the resource-side handover boundary. A stale write that reaches storage before that boundary may still be accepted; the successor must perform a strongly consistent read after fencing, or obtain state in the fencing transaction, so it incorporates the actual stored state. Token ordering alone does not promise rejection at the exact instant a remote lease expires.
Requests within the same generation still need operation IDs and, when necessary, expected-version checks. Permitting token equality allows the legitimate owner to perform several writes, but does not stop a duplicate payment or a delayed earlier write from overwriting a later one. Fencing prevents stale-owner interference; idempotency and resource-version concurrency solve different problems.
If all protected data is inside the coordination store, ownership checks and changes can sometimes share one transaction. The etcd API documents this pattern using the returned ownership key. For an external database or service, an etcd check followed by an unrelated write is not atomic; the external system needs its own compatible enforcement.
4. State what cannot be protected
A third-party endpoint that ignores tokens cannot be made fenced by attaching an extra HTTP header. Use a resource-native conditional operation, an idempotent business operation, or a trusted execution boundary that actually controls the side effect. A gateway that checks a token and then issues an unguarded external request can still have a delayed old request in flight.
If no such mechanism exists, state the weaker guarantee and redesign the workflow, for example as uniquely identified tasks with reconciliation. A lease can reduce duplicate work without being a correctness lock. Do not claim exactly-once external effects merely because one worker usually holds a lock.
Multiple protected resources also need separate reasoning. Installing a token in two databases is not an atomic transfer across both. Use a transactional design where required, or an explicit recovery protocol with compensations and invariants. The lock name alone does not create a cross-system transaction.
5. Balance recovery latency and renewal load
Assume 100,000 independently renewed active leases, each renewed every 10 seconds. That is 10,000 logical renewals/s before acquisitions and releases. With a 30-second nominal TTL, the client has several renewal opportunities, but no fixed TTL guarantees survival of every network delay or process pause.
Jitter renewal times to avoid synchronized bursts and prioritize renewal traffic under load. Sharing one session lease across many resources can lower renewal count, but losing that lease releases ownership of all attached resources together and changes the failure domain. Measure the actual implementation; one logical renewal is not necessarily one independent durable disk write.
Short TTLs can speed healthy-cluster reassignment but cause more ownership churn during transient stalls. Long TTLs can delay recovery. Expiry, leader elections, waiting queues and resource fencing all contribute to handover time, so “30-second lease” is not a guaranteed 30-second recovery objective.
If one hot resource requires 200 ms of exclusive work per holder, sequential throughput is at most five operations/s before coordination overhead. More lock servers cannot remove that serialization bottleneck. Reduce the critical section, partition the resource or replace the lock with a suitable atomic operation when possible.
6. Test the failure boundary
Run a drill that pauses A after reading, lets B acquire and fence, then resumes A's old request. Assert the resource rejects it. Separately test A's write arriving before B's fencing acknowledgment, equal-token retries, stale release calls, authority failover and restored metadata. These cases expose stronger claims than a happy-path acquire/release test.
When quorum is unavailable, do not grant conflicting ownership from isolated replicas to preserve apparent availability. Existing resource token checks still reject older generations already superseded there, but the system may be unable to transfer ownership until coordination recovers. Choose this limitation explicitly for correctness-critical resources.
Bound waiting queues and use cancellation deadlines. Fairness requires a specified queue policy; it does not emerge automatically from polling and backoff. Monitor renewal failures, wait duration, ownership churn, rejected stale writes and time until a successor is usable.
Foundation: explain the paused-worker race. Senior: locate the atomic token check and distinguish duplicate operations. Staff: design recovery when the protected system cannot enforce tokens.
Score 0–2 each for the failure model, ownership authority, resource fencing, timing trade-offs and explicit limitations. Continue with checkpoint publication and job scheduling.
Walk through a resource-side handover
Additional original practice exercise · October 3, 2026. Numbers are illustrative assumptions.
Extend the paused-worker example with an explicit resource version. Storage begins at fencing token 41, data version 8. B installs token 42 and reads version 8 in one transaction. B then writes with token 42 and expected version 8, producing version 9. A sends token 41 and expected version 8: reject it before applying any mutation.
Now B retries its successful write after losing the response. The same operation ID returns the saved result without another effect. If B instead submits a different operation with expected version 8, reject the stale version even though its fencing token is current. These are three independent checks: owner generation, logical operation identity and data version.
Practice: reverse A's write and B's handover. If A commits first, B must read the resulting state after installing its fence. A protocol that promises otherwise needs a stronger shared authority between the lease and storage systems.
Related practice: Design a GPU job scheduler · Allocate tenant quotas across regions
Sources and next steps
- etcd concurrency API — lease-associated ownership, release semantics and transactional ownership checks.
The external-resource fencing protocol and numerical examples are original practice. The cited API does not automatically fence arbitrary external side effects.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.