After Hours Academic

Question 13: 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 coming up in the next post!


Solution for accurate count:

Marie needs to implement some idempotency mechanism to avoid double additions (or subtractions). A common solution is to have the sender (in this case, the server at the garage entry and exit) add an idempotency number to each message. The receiver should log (say in a database) the idempotency number for each of the request it processes. Before processing a request, the receiver should check whether it has already processed a request with the same idempotency number. If so, the receiver can infer that it is a duplicated message and ignore it.

A common choice of idempotency numbers is a randomly generated UUID. In this particular case, Marie can even use the car's license plate number as a unique idempotency identifier for a car entering or exiting the garage. The only additional requirement is that once a car exits the garage, the receiver would need to remove the idempotency identifier for the car (i.e., its license plate number) from the list of its processed messages for the cars that entered the garage. Otherwise a re-entry, following an exit, would also appear as a duplicate message.

AWS has a good blog on idempotency mechanisms here.

#qna