SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Horizontal Scalability for Great Success
                          Nick Barkas
                            @snb

                                        EuroPython - 22 June 2011

onsdag den 22 juni 2011
Outline

        Introduction
          • Spotify
          • Kinds of scalability
        Designing scalable network applications
          • Distributing work
          • Handling shared data
        Related Spotify tools and methods
          • Supervision
          • Round-robin DNS and SRV records
          • Distributed hash tables (DHT)


onsdag den 22 juni 2011
Introduction




onsdag den 22 juni 2011
What is Spotify?
        On-demand music streaming service
        Also play your music files, or buy mp3 downloads
        Premium subscriptions with mobile and offline support, or
        free with ads
        Create playlists available on any computer or device with
        Spotify
        Connect with friends via Facebook and send songs to each
        other
        Sync downloads and your own music files with iPods
        Available today in Sweden, Norway, Finland, UK,
        Netherlands, France, and Spain


onsdag den 22 juni 2011
Overview of Spotify network
                              Backend services        search


                          playlist   storage   user   browse       ...




                                     access
                                                      web api
                                      point




                                                         Clients



onsdag den 22 juni 2011
Scaling vertically: “bigger” machines



    +Maybe no or only small code changes
    +Fewer servers is easier operationally
    -Hardware prices don’t scale linearly
    -Servers can only get so big
    -Multithreading can be hard
    -Single point of failure (SPOF)


onsdag den 22 juni 2011
Scaling horizontally: more machines


    +You can always add more machines!
    +No threads (maybe)
    +Possible to run in “the cloud” (EC2, Rackspace)
    -Need some kind of load balancer
    -Data sharing/synchronization can be hard
    -Complexity: many pieces, maybe hidden SPOFs
    ±Fundamental to the application’s design



onsdag den 22 juni 2011
Why horizontal for Spotify?



        We are too big
          • Over 13 million songs
          • And over 10 million users, who have lots of playlists
        CPython kind of doesn’t give us a choice anyway
          • Global interpreter lock (GIL) = no simultaneous threads




onsdag den 22 juni 2011
Why the GIL is kind of a good thing



        Forces horizontally scalable design
        Multiple cores require multiple Python processes
          • Basically the same when scaling to multiple machines
        Multi-process apps encourage share-nothing design
          • Sharing nothing avoids difficult, slow synchronization




onsdag den 22 juni 2011
Designing scalable network applications




onsdag den 22 juni 2011
Separate services for separate features



        The UNIX way: small, simple programs doing one thing well
          •     Can do the same with network services
          •     Simple applications are easier to scale
          •     Can focus on services with high usage/availability needs
          •     Development is fast and scalable too
                ‣ If well-defined interfaces between services




onsdag den 22 juni 2011
Many instances of each service



        N instances/machine where N <= # cores, many machines
        Need a way to spread requests amongst instances
          • Hardware load balancers
          • Round-robin DNS
          • Proxy servers (Varnish, Nginx, Squid, LigHTTPD, Apache...)




onsdag den 22 juni 2011
Sharding data




        Each server/instance responsible for subset of data
        Can be easy if you share nothing
        Must direct client to instance that has its data
        Harder if you want things like replication




onsdag den 22 juni 2011
Brewer’s CAP theorem

                          Consistency        Availability




                                     Partition
                                    Tolerance




        You only get to have one or two
                                                            Image: http://thecake.info/




onsdag den 22 juni 2011
Brewer’s CAP theorem

                          Consistency        Availability




                                     Partition
                                    Tolerance




        You only get to have one or two. The cake is a lie.
                                                              Image: http://thecake.info/




onsdag den 22 juni 2011
Eventual consistency


        Lots of NoSQLish options work this way
          • Reads of just written data not guaranteed to be up-to-date
        Example: Cassandra
          • Combination of ideas from Dynamo and BigTable
          •     Available (fast writes, replication)
          •     Partition tolerant (retries later if replica node unreachable)
          •     Also can get consistency if willing to sacrifice the other two
          •     But rather young project, big learning curve




onsdag den 22 juni 2011
Sometimes you need consistency



        Locking, atomic operations
          • Creating globally unique keys, e.g. usernames
          • Transactions, e.g. billing
        PostgreSQL (and other RDBMSs) are great at this
          • Availability via replication, hot standby masters
          • Store only what you absolutely must in global databases




onsdag den 22 juni 2011
Tips for many instances of a service




        Processor affinity
        Watch out for connection limits (e.g. in RBDMS)
        Lots of processes can share memcached
        OS page cache for read-heavy data




onsdag den 22 juni 2011
Related Spotify tools and methods




onsdag den 22 juni 2011
Supervision



        Spotify developed daemon that launches other daemons
          • Usually as many instances as cores - 1
          • Restarts supervised instance if one fails
          • Also restarts all instances of an application on upgrade
        See also: systemd




onsdag den 22 juni 2011
Finding services and load balancing



        Each service has an SRV DNS record
          •     One record with same name for each service instance
          •     Clients (AP) resolve to find servers providing that service
          •     Lowest priority record is chosen with weighted shuffle
          •     Clients must retry other instances in case of failures




onsdag den 22 juni 2011
Finding services and load balancing


         Example SRV record
        _frobnicator._http.example.com. 3600 SRV   10    50   8081 frob1.example.com.
                          name          TTL   type prio weight port       host


        Sometimes also use Varnish or Nginx for HTTP services
          • Can have caching too




onsdag den 22 juni 2011
Distributed hash tables (DHT) in DNS
         Service instances correspond to a range of hash keys
                                                     e7
                                                          F
                                                              A   14
                                                                           key k = 1c

                                       c1
                                            E

                                                                       B   3f
                          key j = bd




                                                 D
                                            9e                C
                                                                  68

          • Distributes data among service instances
                ‣ Instance B owns keys in (14, 3f], E owns (9e, c1]
          • Redundancy? Hash again, write to replica instance
          • Must transition data when ring changes
          • Good also for non-sharded data: cache locality

onsdag den 22 juni 2011
DHT DNS record examples

         Ring segment, per instance
      tokens.8081.frob1.example.com. 3600 TXT                        “00112233445566778899aabbccddeeff”
                   name: tokens.port.host.          TTL     type                      last key


         Configuration of DHT
                      config._frobnicator._http.example.com.                3600 TXT      “slaves=0”
                                   name: config.srv_name.                  TTL     type no replication


      config._frobnicator._http.example.com.                       3600 TXT     “slaves=2 redundancy=host”
                          name: config.srv_name.                   TTL   type    three replicas on separate hosts




onsdag den 22 juni 2011
Further reading about DHTs




        “Chord: A scalable peer-to-peer lookup service for internet applications”
          • http://portal.acm.org/citation.cfm?id=964723.383071
        “Dynamo: Amazon’s Highly Available Key-value Store”
          • http://portal.acm.org/citation.cfm?id=1294281




onsdag den 22 juni 2011
One last thing to remember
        /dev/null is web scale!




                                  Image: http://www.xtranormal.com/watch/6995033/




onsdag den 22 juni 2011
Questions?
          Or write me something: snb@spotify.com, @snb on Twitter




onsdag den 22 juni 2011
Thank you




onsdag den 22 juni 2011

Contenu connexe

Tendances

Real-Time Data Flows with Apache NiFi
Real-Time Data Flows with Apache NiFiReal-Time Data Flows with Apache NiFi
Real-Time Data Flows with Apache NiFiManish Gupta
 
Iceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsIceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsAlluxio, Inc.
 
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...Timothy Spann
 
Getting Started with Databricks SQL Analytics
Getting Started with Databricks SQL AnalyticsGetting Started with Databricks SQL Analytics
Getting Started with Databricks SQL AnalyticsDatabricks
 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive QueriesOwen O'Malley
 
Building an open data platform with apache iceberg
Building an open data platform with apache icebergBuilding an open data platform with apache iceberg
Building an open data platform with apache icebergAlluxio, Inc.
 
Hyperloglog Project
Hyperloglog ProjectHyperloglog Project
Hyperloglog ProjectKendrick Lo
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiDatabricks
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
 
Open Source DataViz with Apache Superset
Open Source DataViz with Apache SupersetOpen Source DataViz with Apache Superset
Open Source DataViz with Apache SupersetCarl W. Handlin
 
High Concurrency Architecture and Laravel Performance Tuning
High Concurrency Architecture and Laravel Performance TuningHigh Concurrency Architecture and Laravel Performance Tuning
High Concurrency Architecture and Laravel Performance TuningAlbert Chen
 
Vector databases and neural search
Vector databases and neural searchVector databases and neural search
Vector databases and neural searchDmitry Kan
 
Introduction to Apache NiFi dws19 DWS - DC 2019
Introduction to Apache NiFi   dws19 DWS - DC 2019Introduction to Apache NiFi   dws19 DWS - DC 2019
Introduction to Apache NiFi dws19 DWS - DC 2019Timothy Spann
 
XStream: stream processing platform at facebook
XStream:  stream processing platform at facebookXStream:  stream processing platform at facebook
XStream: stream processing platform at facebookAniket Mokashi
 
Strata sf - Amundsen presentation
Strata sf - Amundsen presentationStrata sf - Amundsen presentation
Strata sf - Amundsen presentationTao Feng
 
Hadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayHadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayDataWorks Summit
 

Tendances (20)

Real-Time Data Flows with Apache NiFi
Real-Time Data Flows with Apache NiFiReal-Time Data Flows with Apache NiFi
Real-Time Data Flows with Apache NiFi
 
Iceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data AnalyticsIceberg + Alluxio for Fast Data Analytics
Iceberg + Alluxio for Fast Data Analytics
 
Apache Atlas: Governance for your Data
Apache Atlas: Governance for your DataApache Atlas: Governance for your Data
Apache Atlas: Governance for your Data
 
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
 
Getting Started with Databricks SQL Analytics
Getting Started with Databricks SQL AnalyticsGetting Started with Databricks SQL Analytics
Getting Started with Databricks SQL Analytics
 
Spotify: P2P music streaming
Spotify: P2P music streamingSpotify: P2P music streaming
Spotify: P2P music streaming
 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive Queries
 
Building an open data platform with apache iceberg
Building an open data platform with apache icebergBuilding an open data platform with apache iceberg
Building an open data platform with apache iceberg
 
Hyperloglog Project
Hyperloglog ProjectHyperloglog Project
Hyperloglog Project
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and Hudi
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Open Source DataViz with Apache Superset
Open Source DataViz with Apache SupersetOpen Source DataViz with Apache Superset
Open Source DataViz with Apache Superset
 
Grafana 7.0
Grafana 7.0Grafana 7.0
Grafana 7.0
 
High Concurrency Architecture and Laravel Performance Tuning
High Concurrency Architecture and Laravel Performance TuningHigh Concurrency Architecture and Laravel Performance Tuning
High Concurrency Architecture and Laravel Performance Tuning
 
Dataflow with Apache NiFi
Dataflow with Apache NiFiDataflow with Apache NiFi
Dataflow with Apache NiFi
 
Vector databases and neural search
Vector databases and neural searchVector databases and neural search
Vector databases and neural search
 
Introduction to Apache NiFi dws19 DWS - DC 2019
Introduction to Apache NiFi   dws19 DWS - DC 2019Introduction to Apache NiFi   dws19 DWS - DC 2019
Introduction to Apache NiFi dws19 DWS - DC 2019
 
XStream: stream processing platform at facebook
XStream:  stream processing platform at facebookXStream:  stream processing platform at facebook
XStream: stream processing platform at facebook
 
Strata sf - Amundsen presentation
Strata sf - Amundsen presentationStrata sf - Amundsen presentation
Strata sf - Amundsen presentation
 
Hadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayHadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox Gateway
 

Similaire à Spotify: Horizontal Scalability for Great Success

Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInLinkedIn
 
Large-Scale Data Storage and Processing for Scientists with Hadoop
Large-Scale Data Storage and Processing for Scientists with HadoopLarge-Scale Data Storage and Processing for Scientists with Hadoop
Large-Scale Data Storage and Processing for Scientists with HadoopEvert Lammerts
 
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017The Hows and Whys of a Distributed SQL Database - Strange Loop 2017
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017Alex Robinson
 
Robust Containers by Eric Brewer
Robust Containers by Eric BrewerRobust Containers by Eric Brewer
Robust Containers by Eric BrewerDocker, Inc.
 
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph Ceph Community
 
Ceph Day NYC: Building Tomorrow's Ceph
Ceph Day NYC: Building Tomorrow's CephCeph Day NYC: Building Tomorrow's Ceph
Ceph Day NYC: Building Tomorrow's CephCeph Community
 
Fabric Data Factory Pipeline Copy Perf Tips.pptx
Fabric Data Factory Pipeline Copy Perf Tips.pptxFabric Data Factory Pipeline Copy Perf Tips.pptx
Fabric Data Factory Pipeline Copy Perf Tips.pptxMark Kromer
 
Building high traffic http front-ends. theo schlossnagle. зал 1
Building high traffic http front-ends. theo schlossnagle. зал 1Building high traffic http front-ends. theo schlossnagle. зал 1
Building high traffic http front-ends. theo schlossnagle. зал 1rit2011
 
H2O Deep Water - Making Deep Learning Accessible to Everyone
H2O Deep Water - Making Deep Learning Accessible to EveryoneH2O Deep Water - Making Deep Learning Accessible to Everyone
H2O Deep Water - Making Deep Learning Accessible to EveryoneSri Ambati
 
Netty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityNetty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityC4Media
 
Open Source SQL Databases
Open Source SQL DatabasesOpen Source SQL Databases
Open Source SQL DatabasesEmanuel Calvo
 
Code Search Based on Deep Neural Network and Code Mutation
Code Search Based on Deep Neural Network and Code MutationCode Search Based on Deep Neural Network and Code Mutation
Code Search Based on Deep Neural Network and Code MutationNorihiro Yoshida
 
OpenPOWER Acceleration of HPCC Systems
OpenPOWER Acceleration of HPCC SystemsOpenPOWER Acceleration of HPCC Systems
OpenPOWER Acceleration of HPCC SystemsHPCC Systems
 
Migrating Social Content to Drupal
Migrating Social Content to DrupalMigrating Social Content to Drupal
Migrating Social Content to DrupalAcquia
 

Similaire à Spotify: Horizontal Scalability for Great Success (20)

Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
RunDeck
RunDeckRunDeck
RunDeck
 
Large-Scale Data Storage and Processing for Scientists with Hadoop
Large-Scale Data Storage and Processing for Scientists with HadoopLarge-Scale Data Storage and Processing for Scientists with Hadoop
Large-Scale Data Storage and Processing for Scientists with Hadoop
 
Pisa
PisaPisa
Pisa
 
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017The Hows and Whys of a Distributed SQL Database - Strange Loop 2017
The Hows and Whys of a Distributed SQL Database - Strange Loop 2017
 
Robust Containers by Eric Brewer
Robust Containers by Eric BrewerRobust Containers by Eric Brewer
Robust Containers by Eric Brewer
 
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph
Ceph Day Santa Clara: Keynote: Building Tomorrow's Ceph
 
Ceph Day NYC: Building Tomorrow's Ceph
Ceph Day NYC: Building Tomorrow's CephCeph Day NYC: Building Tomorrow's Ceph
Ceph Day NYC: Building Tomorrow's Ceph
 
Fabric Data Factory Pipeline Copy Perf Tips.pptx
Fabric Data Factory Pipeline Copy Perf Tips.pptxFabric Data Factory Pipeline Copy Perf Tips.pptx
Fabric Data Factory Pipeline Copy Perf Tips.pptx
 
Building high traffic http front-ends. theo schlossnagle. зал 1
Building high traffic http front-ends. theo schlossnagle. зал 1Building high traffic http front-ends. theo schlossnagle. зал 1
Building high traffic http front-ends. theo schlossnagle. зал 1
 
Http front-ends
Http front-endsHttp front-ends
Http front-ends
 
H2O Deep Water - Making Deep Learning Accessible to Everyone
H2O Deep Water - Making Deep Learning Accessible to EveryoneH2O Deep Water - Making Deep Learning Accessible to Everyone
H2O Deep Water - Making Deep Learning Accessible to Everyone
 
Netty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityNetty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/Connectivity
 
Stardog talk-dc-march-17
Stardog talk-dc-march-17Stardog talk-dc-march-17
Stardog talk-dc-march-17
 
Open Source SQL Databases
Open Source SQL DatabasesOpen Source SQL Databases
Open Source SQL Databases
 
From 0 to syncing
From 0 to syncingFrom 0 to syncing
From 0 to syncing
 
Code Search Based on Deep Neural Network and Code Mutation
Code Search Based on Deep Neural Network and Code MutationCode Search Based on Deep Neural Network and Code Mutation
Code Search Based on Deep Neural Network and Code Mutation
 
OpenPOWER Acceleration of HPCC Systems
OpenPOWER Acceleration of HPCC SystemsOpenPOWER Acceleration of HPCC Systems
OpenPOWER Acceleration of HPCC Systems
 
CERNBox: Site Report
CERNBox: Site ReportCERNBox: Site Report
CERNBox: Site Report
 
Migrating Social Content to Drupal
Migrating Social Content to DrupalMigrating Social Content to Drupal
Migrating Social Content to Drupal
 

Dernier

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

Spotify: Horizontal Scalability for Great Success

  • 1. Horizontal Scalability for Great Success Nick Barkas @snb EuroPython - 22 June 2011 onsdag den 22 juni 2011
  • 2. Outline Introduction • Spotify • Kinds of scalability Designing scalable network applications • Distributing work • Handling shared data Related Spotify tools and methods • Supervision • Round-robin DNS and SRV records • Distributed hash tables (DHT) onsdag den 22 juni 2011
  • 4. What is Spotify? On-demand music streaming service Also play your music files, or buy mp3 downloads Premium subscriptions with mobile and offline support, or free with ads Create playlists available on any computer or device with Spotify Connect with friends via Facebook and send songs to each other Sync downloads and your own music files with iPods Available today in Sweden, Norway, Finland, UK, Netherlands, France, and Spain onsdag den 22 juni 2011
  • 5. Overview of Spotify network Backend services search playlist storage user browse ... access web api point Clients onsdag den 22 juni 2011
  • 6. Scaling vertically: “bigger” machines +Maybe no or only small code changes +Fewer servers is easier operationally -Hardware prices don’t scale linearly -Servers can only get so big -Multithreading can be hard -Single point of failure (SPOF) onsdag den 22 juni 2011
  • 7. Scaling horizontally: more machines +You can always add more machines! +No threads (maybe) +Possible to run in “the cloud” (EC2, Rackspace) -Need some kind of load balancer -Data sharing/synchronization can be hard -Complexity: many pieces, maybe hidden SPOFs ±Fundamental to the application’s design onsdag den 22 juni 2011
  • 8. Why horizontal for Spotify? We are too big • Over 13 million songs • And over 10 million users, who have lots of playlists CPython kind of doesn’t give us a choice anyway • Global interpreter lock (GIL) = no simultaneous threads onsdag den 22 juni 2011
  • 9. Why the GIL is kind of a good thing Forces horizontally scalable design Multiple cores require multiple Python processes • Basically the same when scaling to multiple machines Multi-process apps encourage share-nothing design • Sharing nothing avoids difficult, slow synchronization onsdag den 22 juni 2011
  • 10. Designing scalable network applications onsdag den 22 juni 2011
  • 11. Separate services for separate features The UNIX way: small, simple programs doing one thing well • Can do the same with network services • Simple applications are easier to scale • Can focus on services with high usage/availability needs • Development is fast and scalable too ‣ If well-defined interfaces between services onsdag den 22 juni 2011
  • 12. Many instances of each service N instances/machine where N <= # cores, many machines Need a way to spread requests amongst instances • Hardware load balancers • Round-robin DNS • Proxy servers (Varnish, Nginx, Squid, LigHTTPD, Apache...) onsdag den 22 juni 2011
  • 13. Sharding data Each server/instance responsible for subset of data Can be easy if you share nothing Must direct client to instance that has its data Harder if you want things like replication onsdag den 22 juni 2011
  • 14. Brewer’s CAP theorem Consistency Availability Partition Tolerance You only get to have one or two Image: http://thecake.info/ onsdag den 22 juni 2011
  • 15. Brewer’s CAP theorem Consistency Availability Partition Tolerance You only get to have one or two. The cake is a lie. Image: http://thecake.info/ onsdag den 22 juni 2011
  • 16. Eventual consistency Lots of NoSQLish options work this way • Reads of just written data not guaranteed to be up-to-date Example: Cassandra • Combination of ideas from Dynamo and BigTable • Available (fast writes, replication) • Partition tolerant (retries later if replica node unreachable) • Also can get consistency if willing to sacrifice the other two • But rather young project, big learning curve onsdag den 22 juni 2011
  • 17. Sometimes you need consistency Locking, atomic operations • Creating globally unique keys, e.g. usernames • Transactions, e.g. billing PostgreSQL (and other RDBMSs) are great at this • Availability via replication, hot standby masters • Store only what you absolutely must in global databases onsdag den 22 juni 2011
  • 18. Tips for many instances of a service Processor affinity Watch out for connection limits (e.g. in RBDMS) Lots of processes can share memcached OS page cache for read-heavy data onsdag den 22 juni 2011
  • 19. Related Spotify tools and methods onsdag den 22 juni 2011
  • 20. Supervision Spotify developed daemon that launches other daemons • Usually as many instances as cores - 1 • Restarts supervised instance if one fails • Also restarts all instances of an application on upgrade See also: systemd onsdag den 22 juni 2011
  • 21. Finding services and load balancing Each service has an SRV DNS record • One record with same name for each service instance • Clients (AP) resolve to find servers providing that service • Lowest priority record is chosen with weighted shuffle • Clients must retry other instances in case of failures onsdag den 22 juni 2011
  • 22. Finding services and load balancing Example SRV record _frobnicator._http.example.com. 3600 SRV 10 50 8081 frob1.example.com. name TTL type prio weight port host Sometimes also use Varnish or Nginx for HTTP services • Can have caching too onsdag den 22 juni 2011
  • 23. Distributed hash tables (DHT) in DNS Service instances correspond to a range of hash keys e7 F A 14 key k = 1c c1 E B 3f key j = bd D 9e C 68 • Distributes data among service instances ‣ Instance B owns keys in (14, 3f], E owns (9e, c1] • Redundancy? Hash again, write to replica instance • Must transition data when ring changes • Good also for non-sharded data: cache locality onsdag den 22 juni 2011
  • 24. DHT DNS record examples Ring segment, per instance tokens.8081.frob1.example.com. 3600 TXT “00112233445566778899aabbccddeeff” name: tokens.port.host. TTL type last key Configuration of DHT config._frobnicator._http.example.com. 3600 TXT “slaves=0” name: config.srv_name. TTL type no replication config._frobnicator._http.example.com. 3600 TXT “slaves=2 redundancy=host” name: config.srv_name. TTL type three replicas on separate hosts onsdag den 22 juni 2011
  • 25. Further reading about DHTs “Chord: A scalable peer-to-peer lookup service for internet applications” • http://portal.acm.org/citation.cfm?id=964723.383071 “Dynamo: Amazon’s Highly Available Key-value Store” • http://portal.acm.org/citation.cfm?id=1294281 onsdag den 22 juni 2011
  • 26. One last thing to remember /dev/null is web scale! Image: http://www.xtranormal.com/watch/6995033/ onsdag den 22 juni 2011
  • 27. Questions? Or write me something: snb@spotify.com, @snb on Twitter onsdag den 22 juni 2011
  • 28. Thank you onsdag den 22 juni 2011