A deep dive into the development of Octavia.

A deep dive into the development of Octavia.

This blog was written for the medium blog of SRMKZILLA, do check the organisation out, it has my heart, and I know it deserves your attention too ❤️

#kzoctavia play memories by Maroon 5 because we are about to go down memory lane for this blog!

Before we begin, who is Octavia? Well, she is a music bot that lives in your Discord Server (or Discord Guild as the nerdy kids call it). It is written in TypeScript and is wholly open-sourced under the MIT license. Anyone can clone the codebase and run it on their own servers with minimal effort. She was developed and is maintained by SRMKZILLA, a community that loves open-source tech as much as a developer loves dark mode. Or coffee.

Now, you must be wondering why we developed our own music bot when Spotify and YouTube as well as other music bots like Groovy exist. For that, we must go back to the days when the only classroom we used was a Google product when COVID was at its peak and everyone was forced to work remotely.

SRMKZILLA has its own vibrant discord server where people from different colleges, different domains and interests come together to form a community to share their knowledge and learn more. Since its inception, our Discord Server has come a long way, it has become more inclusive and vibrant with time. Before Octavia and before COVID vaccines, when COVID-19 was very new to us and we were still getting used to the ways of coronavirus, our Discord Server was launched aimed at replicating our physical activities in our University. Offline meets and coding sessions were suddenly halted and we moved everything to our Discord Server. But running a Discord community is a chore. Managing roles, banning and deleting unwanted messages, and generating certificates for our workshops were a lot of work to be done manually. And to fix all of this we came up with Jack! Jack managed roles and had a certificate generator for all workshops and we used Jack for a lot more things. It was used to check in and dynamically create text and voice channels for all of the teams in our annual Hackathon, the same hackathon where the idea to develop Octavia was born.

Every year, SRMKZILLA hosts MOZOHACK, our annual hackathon where teams from across the country build some really remarkable products. Since everything was online in 2021, we used Discord as our primary mode of communication with the teams. During the 24-hour hackathon, there are large stretches of time where teams are in their team voice channels, working on their ideas and writing code. This 24-hour stretch was the reason the idea to develop Octavia came to fruition.

While we accept that Groovy is (rather was) a very well-made product and it served as an inspiration for Octavia, it simply did not fulfill our needs. Some of those were:

  • Groovy’s non-premium version only allowed one instance of Groovy per server. This meant only one voice channel could use Groovy at a given point in time. Which was simply too few for us.
  • Groovy was not open-sourced. In discord, all messages in a guild are sent to the bots and they are actively listening for the wake word.

To overcome these issues we started working on our own music bot and 23 Pull requests, 140 commits, 5 contributors, a few sleepless nights and a dozen missed classes later we had Octavia ready to rock the world. We (and our Linux servers) were overwhelmed by the response to Octavia.

So How did Octavia help resolve the issues we had with Groovy?

Well, first of all, Octavia was completely open-sourced. With minimal configuration, anyone could create as many instances of Octavia as they wish to use. And there was complete transparency with how the data in discord servers are used by Octavia so that you can sleep peacefully while Taylor Swift songs play in the background.

Tech Stack:

The easiest decision we made while developing Octavia was using DiscordJS. DiscordJS is a JavaScript library for using Discord APIs and the developers at SRMKZILLA absolutely adore the documentation and the community support for the library.

We chose DiscordJS because we already had a lot of experience working with DiscordJS while developing Jack (our first Discord bot which moderates our server) and the fact that most of the developers working on the product were very familiar with JavaScript/TypeScript helped reduce the development time.

Discord APIs have tons of official and unofficial wrapper libraries in almost all popular languages be it the high-level, dynamically typed, and interpreted languages like Python or compiled and low-level languages like Rust.

In the end, picking a language is a personal choice and we went ahead with TypeScript and DiscordJS.

While Octavia’s core functionality is playing music, we did not want to limit it to just that. We wanted a bot that could fulfil all your music needs. Be it queueing tracks, fetching lyrics or just copying and pasting your Spotify album links and letting Octavia handle it. To allow all of this to function, we used a suite of APIs listed below:

  • ytdl-core: If DiscordJS is the brain of Octavia, ytdl-core is the heart. It allows us to stream music from our servers to your discord voice channels. DiscordJS has amazing support for handling audio streams, including pausing the audio streams, which turned out to be very helpful in the later stages of development.
  • Spotify API: The first feature we had in mind was to allow users to use their Spotify albums/playlists and export them effortlessly. All a user has to do is write ‘play’ followed by the Spotify link and the bot automatically fetches the list of songs and adds them to the queue! While Spotify does not give API keys, it does provide tokens that last for an hour and we built a simple yet full-proof caching system to use the Spotify tokens to the fullest. We’ll go more into depth about this in our next article.
  • Genius API: Allowing our users to get the lyrics of a particular song was a no-brainer. And what better tool to use for lyrics than Genius?

What would we change about Octavia if we were developing it today?

While Octavia is a very successful product according to our metrics, it doesn’t mean its perfect. There are a lot of things that went wrong because we didn’t consider them at the time of development. Some of them were minor and have already been fixed, for example when Octavia was released, it was unable to recognize commands with more than 1 whitespace. This was fixed by one of our community members and Octavia is a better product for it. Some of the issues are major architectural changes that require either a lot of effort or need Octavia to be developed from the start. A few of them are:

  • Sharding. We never expected the user base to grow so much but looking at the current demand, we would definitely perform sharding. To discord’s credit, it is quite easy to perform instance level sharding by using the sharding manager but at some point, horizontal scaling becomes inefficient and vertical scaling needs to be done.
  • Caching and Database Management: While the use of caching is very limited at the moment, we accept that the bot's caching is not very effective on a bigger scale. At the time of development, we used node cache, which does only instance-level caching. We plan to add new features such as saving music history and sharing queues. For that, something like a separate Redis instance coupled with a persistent database would be more scalable.

Well, that was more or less how we developed Octavia, right here at SRMKZILLA. We believe the first step towards becoming a better open source contributor is accepting that no product ever made is flawless. These imperfections open the way for us to learn and fix them. A small bug or imperfection inspires others to learn and be a part of something bigger than them. That is how a lot of us become better developers. Much like Octavia, we have Jack, another Discord bot who happens to be the hardest working member of the entire Organization. And our curiosity and willingness to develop something better and newer than Jack led us on the path of developing Octavia. SRMKZILLA develops open-sourced and free products like URL shorteners, mass-mailers and so much more. If you happen to share our love for open-source tech, please consider becoming a contributor to our organization and our products. We firmly believe that what you bring to the table is invaluable and extremely unique. So head over to our discord server or our GitHub organization and maybe that one action can ripple into us collaborating into making something bigger and better. And remember, we have only one rule at SRMKILLA, whatever product we make it has to be “Made with 💖”.