Improve App data loading performance || System Design || iOS

Shrawan K Sharma
3 min readJun 19, 2023

In real world end user hate “Loading….” .
End User can’t wait for few seconds to load data.
User need instant result.
User like application which doesn’t show loading options.

Why you hate “IRCTC” website before 5 years ?

You might wonder why Facebook and Amazon applications load so quickly. You can see the data instantly.

Why do your applications take so long to load?

The majority of app’s time is spent loading, fetching, and displaying data.
Let’s take the Feed/Homepage example, which every application has:

You will call the Feed API to fetch data:- /api/feed :-

When you call the feed API, a lot of things happen.

On the frontend,

  • Initially show loader in UI

In the backend,

  • Authentication/authorization
  • Check API access
  • Check a condition to display the feed
  • Logic to find updated data
  • Taking data from 2–3 databases with MySQL/mongodb
  • Manipulating data
  • Filtering data
  • Combining table data
  • Encrypting data
  • Sending data back to the client via a secure channel.

On the frontend,

  • Parsing data
  • Displaying the data in the UI

We need to go through each step whenever we call APIs.

What can be done to reduce the above process for each API?
We need to follow each step to call API’s but we can do some smart work to improve time to load page

We can apply a simple strategy to reduce loading time:-

Pre-fetching and pre-calculated mechanisms to

optimize loading time!

Pre-fetching and pre-calculated:-

  • This can be accomplished both on the backend and on the frontend.

How can we pre-calculate?
- If you want to populate a feed with 1000 followers, 100 groups, and 100 tags. For each feed request, you will get the data in 5 seconds.

To solve this issue, we can pre-calculate the feed for the profile and store it in the cache.

Similarly in Frontend, you can prefetch data before hand.

Let’s suppose that while using Facebook, I visit

  • Open group A
  • Chatting with my friend ABC
  • Open my FAV page
  • Open recent reals

Every time I open Swiggy to order food I open

  • Restaurants near me
  • Veg restaurants
  • Pizza Hut nearby me

Every time I open NewApp I open pages

  • Tech news
  • The latest trend
  • Business news

Every time I open Jira I open pages

  • My team’s task
  • Current sprint
  • Notifications

To improve App data loading performance:-
I will call these API’S beforehand.

You might have questions:-

This might increase the load on the server.
User might not visit pre-fetched pages.

To fix this:-

Prefetch strategy plans will be included for every profile.
Customize the prefetch strategy using analytics data and AI.
Trends in newly registered users visiting the application.

There is another edge case:-

What if the prefetch data is outdated:-

Suppose Swiggy restaurant cannot serve me food after 10pm and I prefetched data at 9:59pm.
- To fix this, we will call prefetched API in detail page but most of the data will be consistent. Like in the restaurant usecase, the status/price of the restaurant will be changed based on time and availability.

Next steps is to implement Database Normalization in IOS:-

Prefetch API data are stored in the local cache. Most of the time, we dump data into the local cache without considering performance implications. When a database is normalized, it will be easier to perform queries and get the required results quickly.

Normalization is a database design technique that reduces data redundancy and eliminates undesirable characteristics like Insertion, Update and Deletion Anomalies. Normalization rules divides larger tables into smaller tables and link them using relationships. The purpose of Normalisation in SQL is to eliminate redundant (repetitive) data and ensure data is stored logically.

If someone ask why 5GB data takes 1 day to complete?
What will be your answer?

--

--

Shrawan K Sharma

iOS App Developer - Frontend(ReactJS) - Building innovative products - MNNIT