Codementor Events

Why should you test your code for nulls, zeros, empty lists etc ?

Published May 23, 2024

I will start with a real classic bug which I have been seeing since more than 6 months. There is the very famous company named Amazon who has not handled this simple case of zero balance in Amazon Pay.

What is Amazon Pay ?
It is a wallet which allows to keep some money to make purchases on Amazon, and also make utility bill payments for services like electricity, gas, internet etc.
You can know more about it at [https://pay.amazon.com/what-is-amazon-pay]

What is the bug ?
Since past 6 months or more, I often see a random popup on my mobile whose wording goes like - "You have unused Amazon Pay balance. Use it for blah-blah-blah ...."

The funny part is - I always see this notification when my Amazon pay balance has been zero for past 10 or more days ! 😃

What is the impact of this bug ?
Embarrassment for Amazon - obviously yes !

There is much more to it !
I do not know the internal architecture of their systems, but from whatever I could understand after reading this article at [https://aws.amazon.com/sns/], there is a notification service in action, which randomly sends notifications to users to use their Amazon Pay balance.

Let us do some back of the hand statistical estimates
If there are 50 million Amazon users, and out of them there are say 110 million users of Amazon pay, and let us further narrow down that 1% out of them are people like me who usually keep zero balance - then the number comes out to be 0.1 million = 100,000 = 100 thousand

So, potentially, there are 100 thousand wasteful and meaningless notifications being raised randomly for users with zero balance in Amazon Pay !!

The cost of such wasteful operations is definitely not zero !!

( Did someone say cost cutting ? 😉 )

In the current era of highly scalable and distributed systems, can we afford to overlook such seemingly harmless corner cases ?

My view is - definitely NO.

What do you think ?

What exactly have they missed in their code ?
Their code most probably looks like

user = selectRandomUser();
sendNotificationToUseAmazonPay(user);

The correct code would be something like this

user = selectRandomUser();
balance = getAmazonPayBalance(user);
if(balance > 0.0){
    sendNotificationToUseAmazonPay(user);
}
Discover and read more posts from Ambuj Kumar
get started
post commentsBe the first to share your opinion