Design restaurant shift scheduling
GustoSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design a scalable scheduling system, specifically focusing on data modeling for temporal availability, handling conflicting shift assignments, and API design for concurrent updates.
Problem Statement
Design a backend system for a restaurant workforce management platform. The system allows restaurant managers to create shifts and employees to claim or be assigned to them.
Functional Requirements
- Managers can create, update, and delete shifts for a specific restaurant location.
- Employees can view available shifts and request to claim them.
- The system must prevent double-booking (an employee cannot be assigned to two overlapping shifts).
- Managers can finalize a schedule, locking shifts so they can no longer be modified by employees.
Non-Functional Requirements
- High consistency for shift claiming (no two employees should successfully claim the same slot).
- Read-heavy workload: Employees check the schedule frequently throughout the day.
- Scale: Support 10,000 restaurants with up to 200 employees each.
Deliverables
- Data Model: Define the core entities (e.g., Restaurant, Employee, Shift, Assignment) and their relationships.
- API Design: Propose endpoints for creating a shift, listing available shifts, and claiming a shift.
- Concurrency Strategy: Explain how you will handle the race condition where multiple employees attempt to claim the same shift at the exact same time.
- Scalability: Describe how you would cache the shift schedule to optimize read performance.
Hints
Hint 1
Consider using database-level constraints or optimistic locking (e.g., version columns) to ensure that a shift can only be claimed by one person.
Hint 2
Think about whether to store shifts in a relational database for ACID compliance or if a NoSQL solution is better for the read-heavy nature of the schedule view.
Hint 3
For the read-heavy requirement, consider a caching layer like Redis to store the schedule for a specific restaurant and period, updating it only when a change is persisted in the primary database.
Follow-up questions
- How would you handle a scenario where an employee calls out sick and the manager needs to re-open a shift that was already claimed?
- How would your architecture change if you needed to support 'preferred' shift notifications for specific employees based on their historical availability?
- What steps would you take to ensure the system remains performant during peak holiday seasons when thousands of managers create schedules simultaneously?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.