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
| Rule | Enforcement |
|---|---|
| Primary identifiers and required mapped fields | Database model |
| One payroll snapshot per tenant/employee/period | Database unique index |
| One weekly-off per tenant/day | Database unique index |
| At most one default policy per tenant | Filtered database unique index |
| One rule key per policy | Database unique index |
| Policy rule belongs to policy | Database foreign key; cascade delete |
| Unique Shift compatibility identity | Database unique index |
| Unique outbox event identity | Database unique index |
| One daily Attendance per tenant/employee/date | Application-only; non-unique index |
| One pending reopen request | Application-only pre-insert query |
| Non-overlapping active assignments | Application-only range check |
| Assignment references a Shift | Application-only lookup |
| Punch/reopen relationship to Attendance | Logical 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.csmicroservices/src/attendance-service/Infrastructure/Persistence.csmicroservices/src/attendance-service/Application/Services/ShiftPolicyCommands.csmicroservices/src/attendance-service/Application/Services/ReopenRequestWorkflow.csmicroservices/src/attendance-service/Infrastructure/PayrollLockClient.cs
Related Articles
See Also
Keywords
- Attendance persistence
- EF Core
- PostgreSQL
Revision Information
- Status: Draft
- Last reviewed: 2026-07-15
- Review cycle: Quarterly