I'm almost certain that Twitter is still using Rails in parts of the stack (they replaced the messaging bus with Scala, or something of that sort). Most importantly, a single Mastodon instance is not supposed to grow as big as Twitter. Lots of smaller instances don't have to deal with the same load as Twitter alone.