A boolean costs us a Crore
It is often the simplest of things and the tiniest of mistakes that haunt us the most. We often find ourselves glaring at a broken piece of code because something extremely trivial crawled under our radar. It is a common occurrence, and as we eventually learnt, one that can prove itself rather costly.
We use a third party service provided by Cloudinary, for handling all our media assets such as images and gifs. Cloudinary has a wonderful option to download optimized versions of these assets from their servers with extreme ease, by merely providing the desired parameters of width, height and quality.
Cloudinary charges us for the bandwidth used to serve the media content. Hence, it should come as no surprise, that we always try to download only the smallest, appropriate size, for any given asset, depending on the platform and network quality.
In our mobile apps , we simply request for the assets by passing the device dimensions and the network quality.
We, as app-developers, play a lot with our code in order to provide a better experience to our users, by displaying high quality image assets. Having said that, we also need to be reasonable about the resources that would be consumed, for high quality versions. Given the considerably vast catalogue that we house, it would be highly impractical to simply serve high quality images for every instance, across our entire user-base, as it would push our Cloudinary resource consumption far beyond our acceptable ceiling. This is when we thought of introducing a boolean flag to chip in the Cloudinary params in the assets’ url. However, due to a missing code block, the boolean flag always resulted in a false value which caused all our apps to download full sized, high-res assets from Cloudinary. This resulted in an understandably large bandwidth usage.
We first discovered this on the second occurrence of a consistent spike in our usage bill, which prompted our revisit of the little code snippet we had introduced. It was then that we realized our folly, and got around to fixing it immediately.
Well, the issue is fixed at this moment, and all is restored to normal.
Thanks to Hriddhi Dey for helping me edit the content!