On-demand Resources

Aastha
iOS Exploration
Published in
3 min readJun 3, 2021

On-demand resources are the app content that is hosted on the App Store, separate from the app bundle, and are downloaded on-demand by the operating system.

Many times, while building iOS apps, we have to add resources such as images, videos or animations, that are rarely loaded. These resources increase the bundle size of the application, therefore impacting the user experience without being actively used.

This problem can be optimized to some extent by careful usage of resources but becomes tricky to tackle when there is no alternative — such as in the case of A/B testing, or the resource is loaded for a particular code flow.

It doesn’t make much sense to overload the app with additional resources for all the users when the target audience is comparatively low. This is where we could make use of “On-Demand Resources” supported by the Apple and iOS operating systems.

On-demand resources solution work by separating the resources from the app bundle and hosting it on the App store. When an app needs a resource that is marked on-demand, the request gets queued to the underlying operating system. After that, the operating system takes care of downloading the resource from the server and releases the request. Furthermore, this resource stays on the device for some time, thus making the access faster.

We wanted to leverage this capability in our app, but before that, we wanted to understand how on-demand resources were performing. We wanted to make an informed decision based on facts.

Now, to understand better how on-demand resources were performing, we tried running an experiment in the application. We started with 3 different types of assets :

  1. Animation — 5 MB
  2. Video — 2.3 MB
  3. Image — 1.2 MB

And captured data around how much time it took for the assets to be downloaded and what were the different errors that we faced while accessing the on-demand resources.

In the image below, you can see our TP50, TP95, and TP99 numbers for different assets. As you can see, for 95% of our users, the animation file, which is our biggest asset by size in the experiment, was downloaded within 9s. The users will have to wait for the assets to be downloaded just like if they were downloaded from any other hosted service, but on-demand resources also provide caching. For the subsequent app launches, the application will not download the asset again, if the asset is already cached.

For any hosted assets, another important data point is the error rate. We saw a total of 777 error events for 286,436 download events, which brings our error rate to 0.27%. But these error events also include the errors where users didn’t have enough storage space. If we exclude these errors (528 as shown in the image below), our error rate for on-demand resources comes down to 0.08%.

An interesting observation we got from these numbers was that 331 users didn’t have enough space on their devices to download the assets. Just imagine, what if we had bundled these resources with our app? They might not be able to even upgrade the app. So for just an experiment, we would have blocked those users from getting critical bug fixes.

You can read more about how to use on-demand resources in your app here.

--

--