Tuesday 15 June 2021

Working with Web Client SDK :: Performance Tips!

 Have you worked with Sitecore Content Hub Web Client SDK [External Integration]? or are you planning to using it with you next project? you will definitely find this post useful, this post will focus on some points that will definitely affect/enhance you application performance, we will discuss APIs calls, properties/meta data loads and workarounds, so keep reading! 


First point you should pay attention to is the load configuration, this included the culture load options, property load options and relation options, with Web SDK you can specific exactly what cultures, properties and relations you want to load, always try to load the least amount of data using the load options and configurations to minimize the overhead on the server.

The minimum you load with your request the faster you can retrieve the data from Content Hub, which makes your application faster, so just load the properties or relations you want or your application needs, never used PropertyLoadOption.All for loading properties, or RelationLoadOption.All for loading relations, this will cause a slow response and slow your integration. 




Second point is Throttling, To ensure system stability, a rate limit of 15 calls (requests) per second, per API Integration User is enforced. Exceeding this rate will result in "429 too many requests" error responses. the point to pay attention for here is the per user, which means that the 15 calls per second limit is per user, so if your application is expected to have too many requests what you can do here is to use multiple users to authenticate and use to request data from content hub and that will definitely enhance your system overall performance. 

So, if you have different routes as example in your application, or you have different permissions based on target or calling entity it would be very useful to use multiple users, that will give you more space for number of requests you can do in a second, if you need to know more about Throttling, click here.



Third point is number of requests you make to Content Hub; you will notice that the more requests you do to get data from Content Hub the more time it takes for your application to respond. for that you have to minimize as much as possible the calls you do to Content Hub. 

If you reached to the point where you can't minimize the number of calls any more and your application still not performing as fast you need to, you have to think of another approach, one thing Content Hub provides is Aggregates, you use Aggregates as a way of calling related entity definitions, data sources, and first-level relations with a single HTTP request; calling the Asset aggregate once saves having to call all these definitions in multiple calls.

If you need to know more about aggregates, I wrote a previous post which explains all what you need to know about aggregates, one thing to mention here is, at the time of writing that post the only way to call aggregates and retrieve data was using Raw.GetAsync but in the new version the SDK provides an Aggregates client to get a specific aggregate for a specific entity, see the following example where Asset is the name of the aggregates defined in Content Hub:



Hope the above helps someone, please feel free to comment or email me if you have any questions or more tips to add to the list. :) 





No comments:

Post a Comment