Matthew Kong

Case studies/BambooHR, 2019 to 2020

Time-off balances and manager approval flow

Serialized balance mutations, idempotent approvals and calendar-aware day math so nobody's leave balance goes negative.

Close-up of stylesheet code on a monitor
  1. Employee UI
  2. Leave request API
  3. Policy and calendar engine
  4. Balance transaction
  5. Approval state
  6. Notifications
  7. Nightly accrual job

Why this work, at that time

Leave workflows depend on consistent balances, time-zone handling and approval history. BambooHR shipped future scheduling for Time Tracking in September 2020, a sign of how much scheduling logic the platform carried.

The problem

Requests had to respect accruals, policy types, holidays and date boundaries, and survive two managers approving at once. Repeated clicks must never decrement a balance twice.

The team and my part

Five engineers: three backend PHP, one React, one tech lead, with QA and an HR-domain PM. I owned the transactional approval path and balance calculation, and wrote the runbook for correcting mis-posted balances.

Data and index design

leave_balance(tenant, employee, policy, hours, version); leave_request(id, tenant, employee, start_date, end_date, state); approval(request_id, actor, decision, time). Unique on (request_id, actor, decision_id).

API and event contract

POST /time-off/requests; POST /time-off/requests/{id}/approve with an idempotency key and expected_version; GET /time-off/balances/{employee_id}. States: DRAFT, SUBMITTED, APPROVED, DENIED, CANCELLED.

Core logic

Compute requested hours in the tenant's locale from calendar dates, not elapsed UTC seconds. Lock or version-check the balance row and write the approval and debit in one transaction. The nightly accrual is idempotent on employee, period and policy.

Implementation sequence

  1. Write acceptance cases for holidays, half-days, negative balances, carryover and daylight-saving transitions.
  2. Define the balance ledger and versioned aggregate so corrections are never silent overwrites.
  3. Implement atomic approval and accrual jobs with conflict retries.
  4. Build an admin correction workflow that creates auditable adjustment records.
  5. Run concurrency fuzz tests and cut over policy cohorts with nightly reconciliation.

Environments and release

Local and staging PHP, MySQL and React; nightly scheduled jobs; production batch dashboards and an incident runbook for erroneous balances.

Failure drill

A manager approves while the accrual job posts. Serialized balance mutation prevents the double-spend. A failed adjustment is reversed with a new audit entry, never by editing the journal.

Scale and targets

Modeled scale

  • About 600 tenants and 70K employees
  • 4.5K leave requests per week, roughly 643 per day
  • Approval write spikes near 25 per second during busy periods

Acceptance targets

  • Zero double-debits from race conditions
  • Accrual batch complete before business hours
  • 99.9% daily accrual reconciliation

Scale figures are the sizing model behind the design. Targets are acceptance criteria, not measured results.

The trade-off I would defend

Strong consistency for balances, asynchronous delivery for email. The source of truth is never eventually consistent.