Synopsis: Random Selection

Let's learn another antipattern by using an example of displaying advertisements on a website.

You’re writing a web application that displays advertisements. You’re supposed to choose a random ad on each viewing so that all your advertisers have an even chance of showing their ads and so that viewers don’t get bored seeing the same ad repeatedly.

Things go well for the first few days, but the application gradually becomes more sluggish. A few weeks later, people are complaining that your website is too slow. You discover it’s not just psychological; you can measure a real difference in the page load time. Your readers are starting to lose interest, and traffic is declining.

Learning from past experiences, you first try ...