Skip to content
Workforce · Engineering Showcase

Domain modelling

Cross-location attendance

How the attendance model evolved from one employee, one store to any eligible employee punching at any location, without double counting or losing history.

Domain modellingAuthorizationData integrityTrade-offs· Four incremental releases

01Problem

The first version assumed each employee works at one home store. In practice, staff cover shifts at other locations, area managers move between the locations they supervise, and some staff work at non-store sites.

Every unplanned visit produced an exception for a manager to clear, and early attempts to model the exceptions risked counting the same working day twice in different stores' reports.

02User Needs

  • Employees: clock in wherever they are actually working, without asking anyone first.
  • Store managers: see their own staff once, and not be held responsible for a visitor's attendance.
  • HR and payroll: one timesheet row per employee-day, in exactly one store's file.

03Constraints

  • Raw punch events are immutable and already record the real location, so history must not be rewritten.
  • Management permissions (which stores a manager may administer) must not grow as a side effect of where someone happened to punch.
  • Adding database enum values is not backwards compatible with older deployed clients, which constrains rollback.
  • The rollout had to be reversible without a data migration.

04Technical Decision

Separate three ideas that the original model blended together: where someone may punch (eligibility), which stores they manage (permission), and which store owns a given working day (reporting).

Eligibility became broad and simple. Any active employee may punch at any active location that presents a valid store code, and the location is resolved on the server from the scanned code. Ownership became a single shared rule: a day spent at one location belongs there only if it was a planned workplace; otherwise it falls back to a temporary assignment, then the home store.

A per-employee authorization feature was prototyped along the way. It was set aside in favour of the universal model because it added administration work without improving the reporting guarantees.

Four iterations

Each step shipped separately and kept the previous behaviour working.

  1. Home store + one-day assignments

    Visits elsewhere need an assignment in advance; others are rejected.

  2. Compatibility foundation

    Fail-closed flag; enum compatibility proven on a disposable database.

  3. Dated workplace assignments

    Several stores per employee with effective dates; history kept.

  4. Supervised stores

    Managers may punch at stores they supervise; eligibility only.

  5. Universal cross-location

    Any active location; one shared day-ownership rule.

Three separate questions

The key modelling decision: stop one field from answering all three.

Eligibility

Where may this person punch? Any active location with a valid code.

Permission

Which stores may they manage? Assigned management scope only.

Ownership

Which store owns this day? Planned single location, else temporary assignment, else home.

05Implementation

  • Iteration 1: a schema and compatibility foundation behind a fail-closed feature flag, with a harness that proved an older client could not read the new enum value. That shaped a rollback plan based on redeploying a newer build with the flag off.
  • Iteration 2: temporal multi-store workplace assignments with effective-from/to dates. A partial unique index enforces one current membership per store, and CHECK constraints keep status and dates consistent. Ended rows are kept, never deleted.
  • Iteration 3: supervised stores grant punch eligibility only. They are never used as a fallback location, so the system never guesses between several stores.
  • Iteration 4: universal cross-location punching. The punch and code-verification endpoints share one location resolver, one day-ownership rule drives dashboards, sweeps and exports, and a derived read-only remark labels cross-location punches.

06Validation

  • A dedicated HTTP-level acceptance suite, added to CI, ran against a disposable database built from migrations.
  • Explicit assertions that a three-location day produces one summary, one timesheet and hours counted once.
  • Negative tests for out-of-radius scans, revoked codes and inactive locations, plus a manual on-site test plan for real QR and location checks.
  • Regression suites for existing punch, exception and export behaviour.

07Outcome

  • Merged and released to production with no schema migration, so a rollback means reverting the code change.
  • The automatic exception for unplanned visits was retired, while genuine missing-punch issues are still raised once, at the owning store.
  • Logged-in, on-site acceptance testing with real store codes was planned as a separate post-release step.

08Lessons Learned

  • Several of the hardest bugs came from one field meaning three different things. Naming eligibility, permission and ownership separately made each rule easy to test.
  • Prototyping the more complex design was useful. It made the simpler rule easy to justify to the business.
  • Proving compatibility on a disposable database before shipping turned a vague worry about rollback into a concrete, documented plan.

Based on the project history and release documentation. Identifiers, credentials, configuration values and open findings are intentionally omitted.

Next case studyEmployee lifecycle management