Status: Accepted (in force). Reconstructed 2026-07-21.
Context
Reports are wide (many columns across many entities) and aggregate (trends, summaries). Running them against the live operational databases would mean expensive multi-join queries and heavy aggregation on the same tables serving day-to-day transactions — slow reports and contention with live operations.
Decision
Build a separate Warehouse database (WarehouseDbContext, resolved by WarehouseDbFactory) with two table shapes:
- Stores — denormalized flat copies of operational data (
PersonStore, PayrollItemSummaryStore, EmployeeRequestStore, ContractorStore, PaymentScheduleItemStore). The joins are pre-done, so a wide report is a single-table scan.
- Containers — pre-aggregated summaries/trends (
EmployeeTrendContainer, GenderSummaryContainer, PayrollTrendContainer, TopPayrollCompaniesContainer), computed by SQL stored procedures (ProcedureExecutionContainer tracks their execution).
Reports and dashboards read the Warehouse; operational writes never touch it directly.
Consequences
Good:
- Fast, wide reports — flattening removes the join cost.
- Instant dashboards — Containers are pre-computed, so trend charts don't crunch live data on each load.
- Isolation — heavy reporting queries don't contend with transactional workloads.
- Aggregation in SQL procedures is efficient for set-based summarisation.
Bad / costs:
- A fourth database to reason about (Tenant + Membership + EWA/warehouse split). A report bug could be in the source data, the sync, the Store, the Container procedure, or the report method — a longer diagnosis chain.
- Duplication — the warehouse is a copy; it must be kept in sync (RFD-002) and can drift on sync failure.
- Logic in SQL procedures — Container aggregation lives in the database, invisible to the C# and harder to test/version (echoes the Performance V1 SP problem).
- Schema changes ripple: an operational field a report needs must be added to the Store and the sync.
Alternatives