There was a post with some technical details on Agar.io a while ago back when it was released (>2 years ago). A year after Agar.io I made Diep.io, which is also fairly successful (but not nearly as crazy as agar.io), so that points to it not being completely based on luck :)
I just make what feels fun. For a perspective on development cycle: the initial version of Agar.io took 1 week, while Diep.io took less than a month too (it was released a lot more polished than agar.io). Of course, they continued receiving updates for months, but the initial version was already fun.
While the initial version for both games was coded fairly quick, there were months of thinking about them before I even started coding, and from beginning of development to first version the gameplay plans didn't change.