What happened when my side project suddenly went viral?
By: Farid Movsumov
Tags: Side Project, Side Hustle, Bots, Monetization, Laravel

My project botmake.io usually had around 1000 daily visitors with quite a stable graph for a long time. It was running on a $10/month DigitalOcean server (2GB memory and 1 CPU) was quite enough for that traffic. The stack of the project is LEMP and it is built with Laravel.

One day I got an email alert notification my website is down 😱. I quickly logged into the server and restarted the PHP-fpm (this always works in panic situations) and the website was up again. Then I quickly checked Analytics if this is happening due to high traffic and yes I saw around 200 people in real-time and the server already was operating on the limits in terms of CPU and memory.

The first thing that came to my mind was to increase the capacity of the server I switched to a $20/mo server (2 CPU and 4GB memory) and was thinking it will be enough to solve the problem. Yes, it helped a bit but traffic also continued increasing and I started to see around 400 people. It was time to increase some limits in configurations as PHP-fpm children, max MySQL connections, etc. After these changes server was able to manage more people but it was going down sometimes. On that night I went to sleep when traffic was around 500 real-time visitors. I couldn’t properly sleep because was worrying about the server. And when I checked Analytics in the middle of the night from my phone I saw 800 real-time users. I wanted to wake up and do something however then laziness won 😅 and I decided to handle in the morning.

The peak moment of the traffic

The next day I decided to get some help from my experienced DevOps Engineer friend Osman, he is working in a game company and everything is about performance in game companies, he has a ton of experience with scaling applications. He suggested some PHP-fpm configuration changes like changing process manager type to static and assign a static number of children (around 100) on startup to decrease CPU usage. And these changes worked quite well for a short time until traffic started to increase again.

I couldn’t find the screenshot when it was 1000 :(

The website started to get around 900 visitors and there were a lot of hiccups. Sometimes because MySql connections weren’t enough and sometimes because PHP-fpm children weren’t enough. The next step was to increase capacity and change configurations for both. After increasing the max allowed number of connections and children this time system started to consume more memory than available. My first reaction was to increase server capacity again. This time I upgraded the server to $40/mo (4 CPU & 8GB Ram) and it was quite a strong machine this time. But even after this upgrade traffic continued to grow and I started to see 1000 real-time visitors.

In parallel to configuration changes I already started doing code optimizations. I added more Redis caching to decrease stress on the database and also made some UX changes to prevent people from sending messages to bots until the bot responded to the previous query. All these changes had some positive effects but weren’t enough as traffic also was increasing.

Then Osman installed some tools on the machine to start sending data to Grafana and we started to see all necessary data in one place and that was helping us a lot. I have never used Grafana before, a really cool tool. There was a single DB query that was not optimized well and waiting a lot and consuming a lot of memory and CPU. It was because of one missing index on the table. After we identified the problem fix just took me 5 minutes to code. After this change memory and CPU usage dramatically decreased.

MySQL indexes are extremely important, learn them very well as a developer.

Then I continued in the same way and found some other queries which could be improved with some indexes. After adding all these necessary indexes to my tables. My application started to be super fast than it has been ever before.

Also special thanks to Tanaydın who taught me a lot about MySQL optimization, he also jumped on Zoom call and helped me to identify one of the complex queries. We solved the last problem and MySQL started to perform really well, in parallel to it all other resource consumptions decreased to the ideal levels.

CPU is operating quite efficiently now. Max peak is 25%

What was the reason for the sudden increase in traffic? 📈

You are probably wondering what was the reason for this sudden increase in traffic to the website. Since botmake.io is the tool for creating chatbots 🤖 and these chatbots always have the potential to go viral. This is what happened. Someone from Spanish-speaking countries created an anime bot and it went viral, people really liked it and started to create their own bots and share their bots on social media platforms like Twitter, Facebook, Instagram, etc.

Bots on the website are listed by popularity and this is the current best bots on the website. Almost all of the anime characters bots. To be honest I have no idea why these characters are so popular.

Top 10 visitor countries.

The funny part is my website is not even in Spanish, it is in English. But users can create their bot independent from language and browser auto-translate features are improved a lot, so language is not the barrier for websites anymore.

How did I use this opportunity to monetize the traffic? 💰

Since most of the traffic was teenagers, I understood it is not going to help my premium package sales and they won’t be able to afford it. Normally it was never in my plans to put advertisements on the website but it was the best option to monetize the teenager traffic. I put some Adsense ads on the website and it started to make some cash. I also sold 2–3 premium packages in that period.

Lessons learned 🎓

Some queries which I forgot to optimize were some features that I added later and I was focused more on functionality and forgot to optimize. When the amount of traffic and data on the database was low it is not possible to notice the slowness but you will notice it at some point. So avoid technical depth while being excited about the new cool features. Always be sure you added correct MySQL indexes.