Design a Lease Service for Electing Leaders of Background Jobs

Last updated: November 29, 2026

Quick Overview

Design a coordination service that Meta's background job owners use to elect a single active leader for a shard of work, with leases, fencing tokens, and fast failover when the leader dies.

Meta
System Design
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
System Design
Medium

0

0

0 solved


Design a coordination service that Meta's background job owners use to elect a single active leader for a shard of work, with leases, fencing tokens, and fast failover when the leader dies.

Many Meta scheduling systems (cron shards, queue pollers, cache warmers) need exactly one active owner per shard, so lease-based election comes up in infrastructure onsites. The interviewer checks understanding of consensus-backed storage, lease timing with clock uncertainty, and fencing to make stale leaders harmless.

What the Interviewer Expects
  • Explain why leases are needed and why a simple lock is not enough
  • Back the service with a consensus store and keep it small
  • Use fencing tokens so a paused old leader cannot corrupt state
  • Choose lease duration and renewal interval with clock skew margins
  • Support thousands of shards with low coordination load
Key Topics to Cover
leases
fencing tokens
consensus
failover
shard assignment
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • What happens if a leader has a 40-second GC pause?
  • How do you balance shards evenly across hosts?
  • How do downstream systems enforce fencing tokens?
  • Why not build this on a cache like memcache?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Functional: clients call acquire(shard) and get a lease with an expiry and a monotonically increasing fencing token, renew(shard, token) periodically, and release. Watches notify waiting can...

High-Level Design

A small consensus cluster (5 nodes running Raft or ZAB, ZooKeeper-like) stores lease/{service}/{shard} = {holder, token, expiry}. Clients talk to it through a client library that handles renewal...


Submit Your Answer
Markdown supported