KatInterview

Building a Crew Rostering Backend with Safe Shift Claiming

System DesignModel answer
MediumModel answerSystem Designsystem-designconcurrencydata-modeling

Last updated

Design a backend for posting, claiming, and locking restaurant work shifts that prevents double-claims and overlapping assignments while serving a heavily read schedule view.

Crew rostering service for restaurants

You are asked to design the backend of a staff-rostering product used by restaurant chains. Managers publish work shifts for their location, and staff members pick up the shifts they want. Once a manager is happy with a week, they can freeze it.

What the system must do

  1. A manager can add, change, and remove shifts for one of their locations.
  2. A staff member can browse the shifts still open and ask to take one.
  3. No staff member may hold two shifts whose time ranges overlap.
  4. A manager can finalize a schedule. After that, staff can no longer change anything on it.

Quality targets

  1. Claiming must be strongly consistent: a slot can never end up with more people than it has capacity for.
  2. The workload is dominated by reads, since staff check their schedule many times a day.
  3. Scale: 10,000 restaurants, each with up to 200 staff.

What to deliver

  1. Data model: the main entities and how they relate.
  2. API: endpoints to create a shift, list open shifts, and claim a shift, including meaningful error codes.
  3. Concurrency: how you guarantee correctness when many people try to claim the same shift at the same moment, and how finalization interacts with in-flight claims.
  4. Read scaling: how you would cache the schedule and keep it reasonably fresh.

State your assumptions and discuss the trade-offs of your choices.

Hints

Hint 1

Start with clarifying questions: can a shift have several slots, can people work at more than one location, and is a claim instant or subject to approval? Then do a quick estimate to see whether volume or contention is the real difficulty.

Hint 2

Push the invariants into the database: a conditional update on a counter for capacity, and an exclusion or unique constraint for overlapping time ranges. Avoid read-then-write logic in application code.

Hint 3

Treat reads and writes differently: the cached schedule can be slightly stale, but the claim path must always validate against the primary database. Think about how finalize and claims coordinate through a row lock on the schedule.

Hint 4

For caching, consider cache-aside with a version number, invalidation driven by committed changes (outbox/CDC) rather than dual writes, ETags, and push notifications to cut polling.