Decoding Software Architecture Of Spotify | TechAhead

Decoding Software Architecture Of Spotify: How Microservices Empowers Spotify

Published datePublished: Jul 13, 2022 ViewsViews: 16517
Ketan Varshneya

Ketan Varshneya

Sr. Tech Architect
Ketan is Senior Tech Lead at TechAhead. He is responsible for leading a development team, and responsible for the quality of its technical deliverables.
Decoding Software Architecture Of Spotify: How Microservices Empowers Spotify

The success and popularity of Spotify have stunned everyone – from the music and entertainment industry to the technology and business world.

Spotify was launched to counter the rising menace of music piracy. It was estimated that 30-40% of revenues generated by the music industry were lost due to piracy, and artists who created original music failed to get fairly compensated for their art.

Understanding these problems, Daniel Ek and Martin Lorentzon from Sweden launched Spotify in 2006, instantly becoming the world’s most popular music streaming service.

Microservices empowers Spotify

With more than 422 million active users and 182 million paid users, Spotify has topped the music streaming industry’s charts and is one of the most preferred and popular platforms for accessing all kinds of music quickly and seamlessly. Spotify is available across 182 nations, hosts 82 million+ songs, and is open to users in free and freemium mode, with revenues generated from advertisements and paid subscriptions.

The Spotify System Model

Unlike the traditional music industry, Spotify has an interesting revenue model, where the artists are paid based on every song sold. With Spotify, record labels who own the rights to the music are paid up to 70% royalty of the revenues generated, and the artists get paid from these record labels directly.

To communicate through the software and use the catalog, Spotify presented its own System Model, which features various entities and abstractions, namely three main ones:

  • APIs: These are the boundaries set between multiple components that define the interface between them
  • Components: Certain instances of a given software (for example, a website, data pipeline, library, etc.)
  • Resources: The backend infrastructure behind each component (database, storage bucket, etc.)

The shared understanding and terminology around software make the Spotify System Model understandable, which is essential for a company of this size.

Microservices empowers Spotify

Decoding The Microservices Software Architecture Of Spotify

Software architecture is the blueprint and the roadmap based on which the entire software is created, and every mobile/digital platform needs a software architecture to start with. Companies usually rely on two types of software architecture: Monolithic Architecture and Microservices.

Spotify is based entirely on Microservices architecture, confirmed and explained by Kevin Goldsmith, the former CTO at Spotify. But first, let us understand the concept of microservices architecture.

What is Microservices Architecture?

Microservices architecture is a style for developing applications that allow the large part of the application to be segregated into smaller independent parts, each delivering its functionality. Thus, when the user prompts a request, a microservices-based application calls one or many internal microservices to respond.

A single service is developed to serve discrete functionality- this is one microservice. Similarly, many microservices are developed simultaneously that solve users’ problems independently or internally communicate with other services. This is a better way to develop and deploy heavy applications.

Where is the Microservices Architecture used?

Since the concept is to break down a complex application into smaller components, Microservices architecture finds use in the following areas:

  1. Website migration: A complex website can be migrated to a cloud-based microservices platform instead of a monolithic platform. This will increase the website’s efficiency with many other development benefits.
  2. Embedding microservices architecture in images and video assets makes the storage more scalable and organized. This makes it quicker to serve the requested images directly to the web or mobile.
  3. Transactions and invoices: If the payment processing and order are segregated as independent services, then payments can still be accepted even when invoicing is out of order.
  4. Data processing: A microservices platform can be extremely efficient because it facilitates multiple services acting independently on data organizing and mining.

“Thousands Of Interlinked Software Systems Owned By Hundreds Of Teams”

Spotify is one of the first few businesses to begin championing the benefits of microservices architectures. It uses a microservices architecture to power its music streaming service. The architecture is composed of hundreds of services that are responsible for different aspects of the application. These services are developed, deployed, and scaled independently, allowing Spotify to iterate and release new features quickly.

The microservices architecture enables Spotify to handle a large traffic volume and multiple teams simultaneously working on different services. Microservices have been instrumental in Spotify’s success as a music streaming service.

Why Does Spotify Employ A Microservices Architecture

The microservices software architecture of Spotify is heavily dependent on services, and this is the reason Spotify’s microservices-based architecture was finalized and worked. The backend of Spotify needs hundreds of services, most tiny and straightforward, but they must be served in run-time without delay.

To serve these hundreds of services, Spotify’s technical team deployed a microservices-based architecture, wherein it serves to address one single service need at a time, Be it song retrieval, sharing recommendations, searching, or simply user verification (for free and paid model).

How Do Microservices Architecture Work & Respond in Spotify?

Services are usually written in Python and/or Java, with few exceptions. They communicate via Hermes protocol, which Spotify has developed from scratch using ZeroMQ and Protobuf.

However, some older services created initially still use HTTP and XML/JSON for communication. For database and storage-based services, PostgreSQL & Cassandra are used by Spotify. Cassandra is preferred for content-based services such as searching the songs or retrieving metadata of the songs in run-time.

A highly specialized backend service called ‘access point’ is constantly in touch with various clients for swift and precise communication. The protocol, which enabled seamless communication between the clients and the ‘access point,’ has also been built by Spotify engineers and hasn’t been made public. Spotify’s Software infrastructure heavily depends on Debian, while open-source software is preferred for various activities.

The Secret Of Swift Music Streaming On Spotify

Now, we have an overview of how services work and respond and have shared why Spotify Microservices-based software architecture has been deployed at Spotify.

Here is a secret about why Spotify can swiftly retrieve songs for the end-users and why music streaming is so fast and reliable. Within the Microservices-based architecture, hundreds of software developers concurrently manage different types of services and their communication.

The secret is that each software developer works in a closed territory with specific functionalities and missions. Every microservice has just one responsibility and objective. Most such microservices have their private database with their logic, and other databases of other microservices cannot intervene with them.

This is why Spotify is so fast and precise and promptly fulfills the end user’s needs. Once a request has been placed for any specific task, the application responds swiftly, deploying different services across different machines and having personalized and customized performance parameters depending on the specific service being called.

Spotify Backend Model: The Seamless Change Management Of Logic

Spotify backend model

What if the software developer needs to change the logic of any feature?

There isn’t any issue of time lag or disruption of the entire application because each microservice has its logic, and implementing changes is very easy. The specific service connected with the feature needs to be worked upon, the edits are made, and only that service is tested and instantly deployed.

Hence, that service has now changed, the logic has altered, and the feature will now have new functionality. This service will start communicating with the application once the deployment is done, and there is no need for the entire application to be re-tested and re-deployed.

This change management feature of microservices being used as the software architecture of Spotify is one of the most vital capabilities that makes Spotify fast and user-friendly.

Interestingly, the software architecture of Spotify has been developed so that all the possible clients of the application, mobile, desktop/laptops, and “libspotify” (Spotify’s embeddable library – Now Sunsetted) all share a common codebase.

Using this joint code base, the developers can modify or enhance the client functionality and offer a unique user interface for the end users.

Since this common code base is written in C++, changes and edits in the main user interface are also easy and seamless. The specific platform adoptions are written in platform-specific languages, for example, ObjC for iOS.

Spotify backend model

Benefits of Using Microservices in Software Development

Microservices software development is one of the popular architectures for software development, with many companies like Spotify leveraging its benefits. Following are some of the essential benefits of using microservices in software development.

  • Scalability:  Microservices allow applications to scale independently based on usage, making handling a large traffic volume easier.
  • Flexibility:  Microservices software development enables developers to use different technologies and programming languages for each service, which can increase the flexibility of the application.
  • Resilience:  Since services are independent, failures in one service do not affect the overall application, which can increase the system’s overall resilience.
  • Maintainability:  Microservices can make it easier to maintain and update the application over time, as you can change individual services without affecting the rest of the application.
  • Agility:  Microservices allow for faster development and deployment of new features, as individual services can be developed and deployed independently.
  • Team productivity: Software development microservices can improve productivity by enabling small, focused teams to work independently on specific services without interfering with other teams.

Overall, it can offer significant advantages in scalability, flexibility, resilience, maintainability, agility, and team productivity, making it a popular approach for modern software development.

Spotify’s Software Visualization Diagrams: The C4 Model

Let’s face it – tech companies just love using diagrams and whiteboards. However, that is a common practice in smaller group settings and not in software systems of scale such as the Spotify app. The engineers at Spotify knew this. They also knew they needed more than just whiteboards that would occasionally get replaced and used interchangeably throughout the firm.

The dilemma of how to visualize the software systems related to the app was solved with a model known as the C4 model. The goal was to understand and visualize the software with minimal context, as well as the main areas that engineers were using as part of it.

The C4 model is a streamlined approach that visualizes software components better. It has become a standard notation for observing software solutions at Spotify, ensuring that the diagrams featuring software components are understandable without additional context. With a selection of software abstractions, Spotify did not want to reinvent the wheel – but rather redefine the set of core diagrams to showcase the incredibly complex network used by millions of users around the globe.

In that manner, C4 perfectly aligns with the Spotify System Model. It brings clear visualization of a broader software ecosystem through three main elements, including:

  • System landscape diagram: This diagram showcases a set of related systems and the connection between each. It also features the external systems they link to and their use within a single domain.
  • System context diagram: A diagram that features the larger context of dependencies, dependents, and users (with specific elements such as user authentication).
  • System components diagram: Finally, this diagram showcases the actual build of the system through individual components and how its resources empower communication. For that, it is also known as the container diagram.

Need A Reliable Audio Streaming App Development Team? Contact Us Today!

If you are looking for audio streaming app development, our TechAhead team can help you immediately.

Based on your specific requirements, we can deploy Spotify-inspired software architecture for your mobile app, loaded with powerful and scalable features.

Schedule an appointment with our Mobile App engineers right here.

back to top