Recently, I was asked by a client to come up with a solution to a problem they were having. They wanted to retrieve a set of notes records from a backend system then use that data to create records for a custom notes entity in CRM. Then, they wanted to display a list of those notes inside a custom HTML web resource. This had to be done in real–time when requested by the user. I noticed a complication when the backend system didn’t have any kind of paging in place. I couldn’t request a subset of records, display them, and request the next page when the user asked for it. I had to make a request to the backend system, get all the records, and then figure out how to get those records into CRM quickly. The user experience depended on it.
The being fetched from the backend system contained a huge number of sometimes 10,000 or more. I wrote an Azure Web App to handle the integration and used the ‘Execute Multiple’ method to speed up creating the records in CRM. This, however, turned out to be only half of the solution. I was still seeing significant delays of up to a minute or more. After digging into the logs and doing some research I found that the biggest delay came from creating the note request and adding it to the request collection. The second half of the solution would have to find some way to improve the performance of loading the request collection.
What was the answer? Multithreading!
By using multithreading, we can leverage multiple CPUs to increase speed. We’re basically trading off CPU load for speed. While the CPU load will increase, the time to perform the actions we need to will decrease.
After I was finished, the time to load and display the notes list decreased from a minute to around 10 seconds. Not too shabby for 10,000 records.
I also realized that this pattern had another application. Data migration. I had another client at the time who needed entity images migrated from their on-premise instance of CRM to the cloud. I was able to use Scribe for most of the data, but entity images were not supported by Scribe. Using this same pattern, I wrote a console app to migrate all of the contact images from their on-prem instance to their online instance.
On to the code!