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
- Write acceptance cases for holidays, half-days, negative balances, carryover and daylight-saving transitions.
- Define the balance ledger and versioned aggregate so corrections are never silent overwrites.
- Implement atomic approval and accrual jobs with conflict retries.
- Build an admin correction workflow that creates auditable adjustment records.
- 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
The trade-off I would defend
Strong consistency for balances, asynchronous delivery for email. The source of truth is never eventually consistent.
