Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Multi-Tenant Employee Leave Management System

Let many companies share one service to manage employees, leave policies, approval workflows, and leave balances, with strict tenant isolation and balances that stay correct under concurrent requests.

Problem statement

For this exercise, assume a software-as-a-service HR product serves many client companies (tenants) from one shared deployment. Each tenant has employees in a reporting hierarchy and defines its own leave types, such as annual leave and sick leave.

For each leave type, the tenant's policy grants a yearly allowance that a scheduled job credits in equal monthly parts, and lets unused days carry over into the next leave year up to a cap.

An employee submits a leave request for one leave type and an inclusive date range; the requested days are the working days in that range under the tenant's weekly schedule and holiday calendar.

Submitting reserves those days from the balance at once, so an employee's pending plus approved days can never exceed what is available, and one employee can never have two pending or approved requests with overlapping dates.

Each request then moves through the tenant's approval rule: one or two ordered approver steps, for example the direct manager and then HR for requests longer than 5 working days. Each approver approves or rejects.

A rejection, or a cancellation by the employee, releases the reserved days; cancelling an approved request before its start date also returns its days.

Employees see their balances and request history, managers see their pending approvals and a team calendar of approved leave, and tenant admins manage employees, reporting lines, leave types, policies, holidays, and approval rules. No user or admin of one tenant may ever read or change another tenant's data.

Design request submission, the approval workflow, balance tracking and monthly accrual, the team calendar, and tenant isolation. Payroll export, attendance tracking, half-day leave, notifications beyond a simple message to the next approver, and changing a policy in the middle of a leave year are outside scope.

What to build

  1. An employee submits a leave request for a leave type and date range; its working days are reserved from the balance at once, the request is refused if it would exceed the available balance or overlap the employee's other pending or approved leave, and a retried submission never creates a second request.
  2. Each request moves through the tenant's ordered approver steps; each approver approves or rejects, and a rejection or cancellation releases the reserved days.
  3. Employees see each leave type's balance (credited, used, reserved, and available) and their request history, and a scheduled monthly accrual credits every employee according to the tenant's policy exactly once per month.
  4. Tenant admins manage employees, reporting lines, leave types, policies, holidays, and approval rules for their own tenant only, and managers see their pending approvals and a team calendar of approved leave.

At scale

  • Assume 20,000 tenants with 10 to 100,000 employees each, about 5 million employees in total.
  • Assume about 200,000 leave requests per day (about 73 million a year, all kept as history), peaking at 300 submissions per second across all tenants; one large tenant can send 2,000 submissions per minute during a company-wide leave window.
  • Balance, history, approval-inbox, and team-calendar reads are about 20 times writes; target p99 below 300 milliseconds for reads and below 1 second for submissions and decisions.
  • A balance must never be overdrawn by concurrent requests, an acknowledged request or decision must never be lost, and the monthly accrual for all 5 million employees must finish within 2 hours.