Why this work, at that time
BambooHR served roughly 11,000 customers across 100 countries by 2019. A multi-tenant HR system lives or dies on accurate employee records and permission-scoped field access.
The problem
Directory data holds compensation, identifiers and contact details. Tenant boundaries and user-level field permissions had to hold in list, detail and exported views alike.
The team and my part
Six engineers: three PHP and API, two React, one senior lead, with QA, product and security review shared. I owned the employee read endpoint and field-policy enforcement, plus a high-severity correctness fix.
Data and index design
employee(tenant_id, employee_id, status); employee_field(tenant_id, employee_id, field_key, value_encrypted); role_binding(tenant_id, user_id, role); field_policy(tenant_id, role, field_key, access). Unique on (tenant_id, employee_id).
API and event contract
GET /employees?cursor&fields; GET /employees/{id}?fields; PATCH /employees/{id} with If-Match. Responses omit disallowed fields entirely and use 403 and 404 consistently so existence never leaks.
Core logic
Resolve tenant and caller from the verified session, load the permitted field mask, include tenant_id in every query, redact forbidden fields before serialization and check update permissions. Append an immutable audit event for sensitive changes.
Implementation sequence
- Create the permission matrix across HR admin, manager, employee and custom roles.
- Refactor directory SQL so the tenant predicate is mandatory at the repository boundary.
- Add the field-scoped serializer and negative authorization contract tests.
- Backfill role mappings with a reversible migration; compare old and new results in shadow mode.
- Launch to pilot tenants; audit the field-access log and missing-data reports.
Environments and release
PHP, MySQL and React local fixtures; per-tenant synthetic staging datasets; production feature flag with least-privilege access to restricted columns.
Failure drill
A shared query omits tenant_id or returns a salary field to a manager without rights. Default deny, disable the endpoint, audit accessed records and run the security incident process.
Scale and targets
Modeled scale
- About 420 tenants and 55K employee profiles in the cohort, 1.4M historical field records
- 250K profile reads per day, 2.9 per second average, roughly 190 per second peak
- About 9K profile updates per day
Acceptance targets
- Zero unauthorized fields across the access matrix
- Directory p95 under 300 ms
- 99.9% service uptime
The trade-off I would defend
Centralized field-level authorization replaced scattered UI checks. UI hiding is a convenience, never a security boundary.
