I started work on the Cider API almost 9 months ago as of the witing of this post. At this point in time, the api did nothing more then serving up a apple music developer token. As we gained more clients, the Musixmatch lyrics inside the app seemed to be a very big bottleneck, sometimes taking up to 2 seconds to serve up lyrics. This was very unacceptable, and also caused rate limits for some people who was using cider at the time.

What is Musixmatch?

From my understanding, Musixmatch is a service that is used to get lyrics from a song, using its musicmatch identifier. Apple itslef uses musixmatch for their Apple Music lyrics as well. This service also happens to come with a pretty heavy cost, which the Cider team cannot afford.

Ring around the rosie

Due to how musixmatch works, we can actually request a trial key to use. In our api, during startup, we fill up a pool of MXM tokens, then for each request, we pick a token such that it is the oldest one iterated though, thus giving attiquit time for the tokens rate limit to pass.

package main
const tokenLimit = 100
var (
	tokenIndex = 0
	tokens [tokenLimit]string

func FillTokens() {
	var tempTokens [tokenLimit]string
	for i := 0; i < tokenLimit; i++ {
		tempTokens[i] = GetMXMToken()
	tokens = tempTokens
	tokenIndex = 0

func GetMXMToken() string {
    return "..."

func PullMXMToken() string {
	token := tokens[tokenIndex]
	if tokenIndex < tokenLimit-1 {
	} else {
		tokenIndex = 0
	return token

Doing it this way, makes sure that everyone can use tokens fast, there is no need to wait on the request for each MXM token, because there are already a ton stored in memory being looped through. The pool is updated every 5 minutes, always making sure that there are always valid tokens able to be used. All of this happends asynchronously.

Cider API

The api itself hosts many endpoints to be used, all private of course. It is able to server up the Musixmatch token and send lyrics directly to the client without the client having the MXM token. All Cider has to do is send the song id, the lyrics type, and the language. The api will then send the lyrics response back as soon as it recives the lyrics.