MSBA-343 · Lesson 12 of 12 · 19 min
Case study: fixing a slow posting process
▶ Video coming soon A video version of this lesson is on the way.
The final clinic was a case study, and it was the case that had been running underneath the whole series: product receipts for large casting orders that took four minutes to post. Desmond asked Prudence to run it from start to finish as if he were not in the room, using every tool from the previous eleven sessions, and to present the result to Kiri, Thandeka and Piotr. He would only interrupt if she skipped a step. This lesson follows her work and the decisions she made along the way.
The problem as reported
The ticket from the second migration rehearsal said the receipt screen freezes. Prudence's first job was to turn that into something measurable. She spoke to the receiving clerk at the Hamilton plant who had raised it, and to Henrik Salo at the Calgary warehouse, who had seen the same thing on a smaller scale. Both described the same pattern: receipts for orders with a few lines were fine; receipts for casting orders with a hundred lines or more took minutes, and the browser showed the spinning indicator the whole time. Orders without castings were fine at any size.
That last detail pointed to the inspection certificate feature from MSBA-341, which only acted on casting lines. Prudence wrote the scenario down as Desmond had taught: purchase order PO-CRCA-001842 with 312 lines, 140 of them castings requiring inspection, 120 with received certificates, 12 waived and 8 with no certificate yet, received in full by a test user holding only the receiving clerk role, in UAT with rehearsal data. Kiri set the target: a receipt of that size should post in under 45 seconds, because the clerks received at most two such orders a day and had agreed they could wait that long.
Step 1: measure
Prudence captured two traces in UAT with the System tracing user role, without SQL parameter values: the full 312-line receipt and a 20-line receipt from a similar order. The full receipt took 236 seconds. The 20-line receipt took 16 seconds. Fifteen times the lines had cost almost fifteen times the time, which told her the cost grew in proportion to the number of lines rather than coming from fixed overhead.
In Trace Parser she sorted the X++ view by inclusive time and read the Call Tree beneath the posting class. The time divided into four parts. The custom receipt check, CRInspectionReceiptRule.isSatisfied, called once per line, took 171 seconds. Inserting rows into the alert queue, one insert per casting line without a certificate, took 38 seconds even though only 8 lines were affected, because the code inserted and then deleted placeholder rows for every casting line. Standard posting took 27 seconds. Everything else was negligible.
| Part of the receipt | Calls | Inclusive seconds | What the trace showed |
|---|---|---|---|
| CRInspectionReceiptRule.isSatisfied | 312 | 171 | A select on CRInspectionCertTable per line with no supporting index; a PurchTable find per line; the category map rebuilt per line |
| Alert queue maintenance | 140 inserts and 132 deletes | 38 | Row-by-row inserts and deletes; data event handler and database log forced per-row processing |
| Standard posting | Not applicable | 27 | Expected cost of posting 312 lines |
| Total | 236 |
Step 2: find the causes
Prudence went through the expensive parts one at a time and wrote down a cause for each, with evidence from the trace. The certificate select used PurchId and LineNumber in its where clause, but CRInspectionCertTable had been created in MSBA-341 with only a primary key on the certificate ID and an index on heat number. With several thousand certificates from the rehearsal, each select scanned the table. The PurchTable find was repeated on every line to read the vendor account for the rule, although every line belonged to the same order. The rule also asked the inspection category map for the item's category on every line, and the map was being rebuilt from three setup tables each time because nothing cached it.
The alert queue had a design flaw from MSBA-341. The original code inserted a pending alert for every casting line as the receipt began, then deleted the ones whose certificates turned out to be satisfied. That was 272 database operations to leave 8 rows. Worse, the queue table had an onInserted data event handler that set a timestamp, and an administrator had enabled the database log on the table during testing. Both forced every insert and delete into row-by-row processing.
Desmond interrupted only once at this stage, to ask whether she had checked that the receipt rule's logic was still correct for the Waived status. She had: the unit tests from lesson 6 covered it, and she ran them before changing anything, so she would know if a fix broke the rule.
Step 3: fix one thing at a time
Prudence made the fixes in an order chosen so that each could be measured on its own, all in her developer environment with a copy of the rehearsal certificates and the same purchase order.
Fix 1: an index. She added a non-unique index, CRPurchLineIdx, on PurchId and LineNumber to CRInspectionCertTable, and changed the select to fetch only RecId and Status with firstonly. Before adding it she checked that no synchronization risk existed: a non-unique index on existing data cannot fail for duplicates. The receipt check fell from 171 seconds to 23.
Fix 2: read the header once. She changed the receipt wrapper to read the purchase order header and the vendor once and pass them into the rule, removing 311 finds. The check fell to 17 seconds.
Fix 3: cache the category map. She cached the category map in the global object cache, keyed by company, with a clear method called from the setup form, as in lesson 5, and changed the rule to read the inspection parameters through the table's find method so that the EntireTable cache answered it. The check fell to 6 seconds.
Fix 4: queue only what is needed, as a set. She replaced the insert-then-delete design with a single insert_recordset that used a notexists join to insert alerts only for casting lines with no Received or Waived certificate. With Thandeka's agreement, the database log on the technical queue table was switched off, and the onInserted handler was removed because the statement now set the timestamp itself. A trace confirmed that the statement ran as one SQL statement. Alert queue maintenance fell from 38 seconds to under one.
A fix she rejected
Between fixes 1 and 2, Prudence had tried an index hint on the certificate select, to force the new index. The trace showed no improvement: the database was already choosing the index. Index hints are also ignored unless enabled in the environment, and Microsoft discourages them. She removed the hint and noted in the pull request that she had tried it and why it was removed. Desmond said that note was worth as much as the fixes, because the next developer would not try it again.
Step 4: test
Each fix came with tests. The index needed none of its own, but the existing rule tests ran after it. Reading the header once changed the rule's method signature, so she updated its tests and added one that checked the rule with lines from two different orders, which the new design had to reject. The cache got the cross-company test from lesson 5. The alert queue got the four status tests from lesson 6, including the Waived case. All forty-seven existing tests and the six new ones passed in Test Explorer and in the pull request's build validation.
Security needed a check as well. The new insert_recordset ran inside the receipt, in the receiving clerk's context. Prudence confirmed with the test user that the clerk role could still post receipts, that the alert job still ran under its service account, and that no XDS policy applied to the queue or certificate tables, so the set-based statement would behave the same for every user.
Step 5: build, deploy and run the regression suite
The pull request listed the new index and the trace that justified it, the removed handler, the database log change agreed with Thandeka, the tests, and a note that no RSAT recording used the changed forms. Thandeka was added as an optional reviewer because the change touched the alert job's data, and Desmond reviewed the code. After merging to main, the change was cherry-picked into the release branch with Kiri's approval, because it fixed a defect found in rehearsal.
The pipeline built the release branch and produced both packages. The Lifecycle Services package went to the asset library and was applied to UAT outside training hours; synchronization created the new index without incident. Annelise ran the RSAT suite, including the casting receipt chain from lesson 7, in all three companies. Every test passed. Prudence then repeated the baseline trace in UAT with the same purchase order. The receipt posted in 31 seconds. The developer environment had shown 34; UAT's slightly faster servers accounted for the difference.
| Measure | Baseline | After fixes |
|---|---|---|
| Total receipt time, 312 lines | 236 seconds | 31 seconds |
| Receipt check, inclusive | 171 seconds | 4 seconds |
| Alert queue maintenance | 38 seconds | Under 1 second |
| Database operations on the alert queue | 272 | 1 |
| Standard posting | 27 seconds | 26 seconds |
Step 6: watch it in production
The fix would not be finished until it was seen working in production. Prudence added the metric from lesson 11, CRReceiptInspectionCheck, which recorded the check's duration on every receipt, and the daily ninety-fifth percentile query to the support workbook. The alert rule for a ninety-fifth percentile above two seconds was set up before go-live, so the support team would know if the check slowed down again as the certificate table grew through 2027. She also added the 312-line receipt to the performance baseline from lesson 3, so that every future release and service update would be measured against it.
The presentation
Prudence presented to Kiri, Thandeka and Piotr in fifteen minutes. She showed the scenario, the baseline trace, the four causes, the chart of each fix against the target, the tests and the RSAT results, and the telemetry that would watch it in production. Piotr asked whether the plants could now receive the largest orders without warning the clerks; she said yes, up to the volumes tested, and that the alert rule would warn the team if that changed. Thandeka asked about the database log; Prudence showed the note recording her agreement and the reason. Kiri closed the performance line on the checklist.
Desmond's summary for Prudence was short. None of the fixes had been clever. Each came from a measurement, each was small enough to review, each was tested, and each was shipped through the same pipeline as everything else. That, he said, is most of what a finance and operations developer does about performance, and most of what the exam expects a developer to know.
Where this course meets the exam
The MB-500 skills outline as of December 18, 2026 puts security and performance in a domain of its own, weighted 10 to 15 percent, and places application lifecycle management under the architecture domain and testing under the code domain. The table maps this course to those areas. MSBA-348, MB-500 Exam Readiness, reviews all domains with practice questions.
| MB-500 area | Lessons in this course |
|---|---|
| Implement security policies and requirements | 1 role-based security; 2 extensible data security |
| Apply fundamental performance optimization techniques | 4 set-based operations and temporary tables; 5 caching, global cache and singletons |
| Optimize performance | 3 indexes and Trace Parser; 5 async and sandbox frameworks; 12 case study |
| Perform testing | 6 SysTest and Task recorder |
| Manage source code and artifacts | 8 Azure DevOps and GitHub version control |
| Implement application lifecycle management | 7 regression testing; 9 packages and environments; 10 lifecycle tools; 11 monitoring |
Worked problem
Applying the method to a new complaint
In the first week of hypercare, Clemency's team reports that posting vendor invoices for casting orders is slow. Using the method from this case, what should Prudence do first, and what should she avoid?
Show solution
- Write the scenario: which invoices, how many lines, which company, which user role, and how long it takes.
- Check telemetry and batch history for a pattern, such as a time of day or a clash with another job.
- Capture a trace of the scenario in UAT with production-like data, without SQL parameter values.
- Find causes in Trace Parser with evidence before changing code, and check unit tests cover the logic involved.
- Avoid guessing, adding hints or skip methods without measurement, or deploying a fix that has not passed the pipeline and regression suite.
Answer: The same disciplined loop applies to any slow process: measure, find causes with evidence, fix and test one change at a time, ship through the pipeline and watch the result.
Common mistakes
MistakeFixing several suspected causes at once.
InsteadFix one thing at a time and measure each, so you know what worked.
MistakeKeeping a change that a trace showed did not help.
InsteadRemove it and record why, so others do not try it again.
MistakeSwitching off auditing on a table without asking the person responsible.
InsteadAgree changes to database logging with the auditor and record the reason.
MistakeCalling a performance fix done when UAT is fast.
InsteadAdd telemetry and alerts so production keeps proving it.
Summary and key terms
- A performance case starts by turning a complaint into a written scenario with a target.
- Traces divide the time into parts, and each cause is written down with evidence before code changes.
- Indexes, reading data once, caching and set-based statements each removed a measured cost.
- Tests, a security check, the pipeline, deployment and the RSAT suite protected correctness while the code changed.
- Telemetry, an alert rule and the performance baseline keep watching the process after go-live.
- Performance target
- An agreed time within which a process must complete for a stated scenario.
- Baseline
- A recorded measurement used to compare later changes.
- Root cause
- The underlying reason for a problem, as opposed to its symptom.
- Cherry-pick
- Copying a specific commit from one branch to another, such as a fix into a release branch.
- Hypercare
- The period of intensive support right after go-live.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why did Prudence trace a 20-line receipt as well as the full one?
Show answer
To see how the cost grew with the number of lines.
Why was the index hint removed?
Show answer
The trace showed no improvement, the database already chose the index, and hints are discouraged.
What keeps watching the receipt check after go-live?
Show answer
A telemetry metric, a daily percentile query and an alert rule.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.