Skip to main content

Attendance Data Integrity and Transactions

Summary

A unit-of-work save is the local aggregate commit boundary. Database constraints protect selected invariants; other rules depend on application validation and must be tested for races.

Audience

  • Backend developers, QA engineers, architects, and reliability reviewers

Enforcement matrix

RuleEnforcement
Primary identifiers and required mapped fieldsDatabase model
One payroll snapshot per tenant/employee/periodDatabase unique index
One weekly-off per tenant/dayDatabase unique index
At most one default policy per tenantFiltered database unique index
One rule key per policyDatabase unique index
Policy rule belongs to policyDatabase foreign key; cascade delete
Unique Shift compatibility identityDatabase unique index
Unique outbox event identityDatabase unique index
One daily Attendance per tenant/employee/dateApplication-only; non-unique index
One pending reopen requestApplication-only pre-insert query
Non-overlapping active assignmentsApplication-only range check
Assignment references a ShiftApplication-only lookup
Punch/reopen relationship to AttendanceLogical only; no foreign key

AttendanceDbContext.SaveChangesAsync converts queued domain events to outbox records before EF commits, so those tracked rows share the local save transaction. Explicit audit/timeline writes included in the same save also participate. Some commands save business state before adding identifier-dependent audit history, creating more than one commit; atomicity across those saves is not guaranteed.

No EF concurrency token or row-version mapping is confirmed. External Payroll lock calls occur outside the PostgreSQL transaction. Cross-service failures require retry/reconciliation rather than database rollback.

Source References

  • microservices/src/attendance-service/Infrastructure/AttendanceDbContext.cs
  • microservices/src/attendance-service/Infrastructure/Persistence.cs
  • microservices/src/attendance-service/Application/Services/ShiftPolicyCommands.cs
  • microservices/src/attendance-service/Application/Services/ReopenRequestWorkflow.cs
  • microservices/src/attendance-service/Infrastructure/PayrollLockClient.cs

See Also

Keywords

  • Attendance persistence
  • EF Core
  • PostgreSQL

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-15
  • Review cycle: Quarterly