The system. A sales warehouse that carries operational order processing and the reporting over it. That combination is the interesting part: the two workloads want opposite things from the storage format, the isolation level and the indexing strategy, and reconciling them is the engineering.
Three invariants must hold:
- Every order line references an order and a product that exist, and quantities and prices are non-negative.
- Any aggregate - a daily sales rollup, a materialised summary - agrees with the detail rows beneath it.
- The reporting workload cannot block the operational one, demonstrably, under concurrent load.
What is assessed. 20% knowledge checks, 35% laboratory portfolio, 15% troubleshooting practical, 30% capstone. The capstone is marked on three things.
Correctness under concurrency. Your test must run reporting queries and order placement simultaneously, and show both the invariants holding and the reports not blocking the writes. If you solved that with NOLOCK, you have not solved it, and the module 3 laboratory should have convinced you why.
Measured performance against a declared baseline. Declare it first - instance size, dataset size, workload mix, and the p50, p95 and p99 for order placement and for your three slowest reports. Then measure. Include the effect of your columnstore decision on both workloads, because it will have helped one and hurt the other.
A defensible account of failure modes and limits. Primary failure mid-order. A log backup job that silently stopped. A statistics update that changed a plan at 09:00 on a Monday. A reporting query that consumed all of tempdb. For each: what happens, what the user sees, what the operator does.
Deliverables: architecture diagram; data model with the argument for the model chosen over the one rejected, including the clustered index decisions; source code; reproducible test dataset; benchmark report; security review; recovery runbook with measured RPO and RTO from an actual restore; and a short design defence.
The design defence is where marks are lost. Name the trade-off you are least comfortable with - for this capstone it is usually the decision to serve reporting from the same instance as transactions, and the honest answer involves a readable secondary.
-- ================= Invariants, as runnable assertions ==============
-- Put these in a job and run them after every deployment and restore.
-- 1. Referential and domain integrity.
SELECT 'orphan_lines' AS check_name, COUNT(*) AS violations
FROM sales.order_line2 AS l
WHERE NOT EXISTS (SELECT 1 FROM sales.[order] o WHERE o.order_id = l.order_id)
UNION ALL
SELECT 'negative_values', COUNT(*) FROM sales.order_line2
WHERE quantity <= 0 OR unit_price < 0;
-- Expected: zero in both.
-- 2. Rollups agree with the detail.
SELECT r.sales_date, r.total_revenue AS rolled_up,
d.total_revenue AS derived
FROM sales.daily_rollup AS r
CROSS APPLY (
SELECT SUM(l.quantity * l.unit_price) AS total_revenue
FROM sales.[order] o
JOIN sales.order_line2 l ON l.order_id = o.order_id
WHERE CAST(o.ordered_at AS date) = r.sales_date
) AS d
WHERE r.total_revenue <> d.total_revenue;
-- Expected: no rows.
-- 3. The physical structure is sound.
DBCC CHECKDB('SalesWorkshop') WITH NO_INFOMSGS, ALL_ERRORMSGS;
-- ================= The concurrency test that matters ===============
-- Reporting and order placement AT THE SAME TIME. Run both for ten
-- minutes and assert that neither blocked the other:
SELECT r.session_id, r.blocking_session_id, r.wait_type, r.wait_time,
OBJECT_NAME(p.object_id) AS blocked_on
FROM sys.dm_exec_requests r
LEFT JOIN sys.partitions p ON p.hobt_id = r.wait_resource_hobt_id
WHERE r.blocking_session_id <> 0;
-- Expected during the run: no rows, or waits in single-digit ms.
--
-- If you achieved that with NOLOCK, you have not achieved it. The
-- reports are then returning rows twice and missing others under the
-- concurrent inserts, silently. READ_COMMITTED_SNAPSHOT, or a
-- readable secondary, is the real answer.
-- ================= Declare the baseline BEFORE measuring ===========
--
-- Instance: 8 vCPU, 64 GB, Developer Edition, premium SSD
-- Dataset: 5,000,000 orders, 20,000,000 lines, 3 years
-- Workload: 70% reporting reads, 30% order placement
-- Claim: place_order p99 < 40 ms at 200 clients
-- daily revenue report p99 < 2 s
-- top products, 90 days p99 < 5 s
-- throughput > 1,500 orders/second
-- log backup RPO <= 15 minutes
-- restore RTO <= 30 minutes, measured
--
-- Then measure, and report the one that missed. There is always one.
-- ================= Failure modes, with the detection ===============
--
-- primary fails mid-order
-- in-flight transactions roll back; a synchronous replica loses
-- nothing, an asynchronous one loses its lag
-- -> measure the lag and declare it as the RPO
--
-- log backup job silently stops
-- the log grows until the disk fills, and nothing alerts
-- -> alert on log_reuse_wait_desc = 'LOG_BACKUP' and on log % used
SELECT name, log_reuse_wait_desc FROM sys.databases
WHERE log_reuse_wait_desc = 'LOG_BACKUP';
-- statistics update changes a plan on Monday morning
-- -> Query Store regression report; force the previous plan
--
-- reporting query consumes tempdb
-- -> alert on tempdb free space; consider Resource Governor
SELECT SUM(unallocated_extent_page_count) * 8 / 1024 AS tempdb_free_mb
FROM tempdb.sys.dm_db_file_space_usage;
-- Verify after EVERY recovery with the three assertions above. "The
-- instance came up" is not verification that the data is right.
Discussion
No questions on this topic yet. Sign in to ask the first one.