Question 14: Faster photos
Anthony is an avid photographer and to share his interest, he has built a mobile app that shows his photos to its users. Anthony has uploaded all his photos to his server (and he keeps adding to it every once in a while). The app shows photos in a random order to the user. When a user uses the app, the app chooses a random index and fetches that photo form the server. If the user wants to see another photo, the app repeats this process.
His users have complained that when trying to view multiple photos, each photo takes a while to show up. Anthony has added some monitoring in his app and knows that on an average, his users view 27 photos in one session. He has asked your help to fix his problem of slow photo downloads. What do you suggest Anthony should do?
Solution
Anthony can speed up his photo viewing app by batching the request to the server. The mobile client can generate a number of random indexes (27 might be a good starting point because that is the average number of viewed photos) and send them all at once to the server. Or the client could just tell the number of images it wants and the server could itself generate a set of random indices. The server would then send all the photos in a single message. The client would cache the images and show them to the user without incurring a network round trip latency for each new photo.