SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Downloaden Sie, um offline zu lesen
Breaking the Monolith
Microservice Extraction at SoundCloud
Soundcloud
● 11 hours uploaded every minute
● 150 million tracks
● 300 million users
2
History
● Rails 2.3
● MySQL
● S3
3
What happened then?
4
Success!
5
History
● Rails 2.3
● MySQL
● AWS
● Cassandra
● Hadoop
● SolR
● RabbitMQ
https://developers.soundcloud.com/blog/evolution-of-soundclouds-architecture
6
Still not enough
● More servers
● Add caching layer
● Defer long running tasks to workers
7
Still not enough
● Optimize database schema
● Introduce read slaves
● Dedicated databases for some models
8
Monolith
9
Major pain points
● Testing, building and deploying
● Dependency hell
● “I’d rather not touch this”
10
Rails problems I - No service layer
11
<% Category.all.each do |cat| %>
<li><%= cat.name %></li>
<% end %>
Rails problems I - No service layer
⇒ Tight coupling with storage layer!
12
<% Category.all.each do |cat| %>
<li><%= cat.name %></li>
<% end %>
Rails problems II - Active Record Magic
13
class User < ActiveRecord::Base
validates_length_of :username, :within => 2..64
before_save :encrypt_password, :accept_terms_of_use
has_many :comments, :dependent => :destroy
# ...
end
Rails problems II - Active Record Magic
⇒ Easy to write, hard to maintain
14
class User < ActiveRecord::Base
validates_length_of :username, :within => 2..64
before_save :encrypt_password, :accept_terms_of_use
has_many :comments, :dependent => :destroy
# ...
end
Ruby Problems
● GIL
● Native extensions
● Dependency management can be painful
15
Extract features as Services
● Less painful to maintain
● Easy to replace
● Fun to build
17
An Example: Messages
● 200 million messages
● MySQL database on shared host
● Features:
○ embedded sounds
○ email notifications
○ spam detection
18
Migration Requirements
● New schema to support upcoming features
● Dedicated database
● Zero downtime
19
Chapter 1
The Database
Migrating the Schema
21
Migrating the Schema
22
Migrating the Schema
Convenient Dependency Management with @Grapes
23
#!/usr/bin/env groovy
@Grapes([
@Grab(group='org.yaml', module='snakeyaml', version='1.12'),
@Grab(group='mysql', module='mysql-connector-java', version='5.1.24')
])
import groovy.sql.Sql
import org.yaml.snakeyaml.Yaml
Strategy
● Import all messages
● Setup cron job to get new messages
● Listen to events for updates
24
Chapter 2
The Application
Creating a new service
26
Convo
● Scala
● Twitter Finagle
● Scalatra Framework
27
Convo architecture
28
Scala
● Functional
● OOP
● Static but inferred typing
29
Scala Joy = Options I
Good bye NullPointerException
30
val opt: Option[String] = params.get("id")
val id: Int = opt.map(id => id.toInt).getOrElse(10)
Scala Joy = Options II
Safe chaining with for comprehensions
31
for {
id <- params.get("id")
user <- users.lookup(id)
count <- counts.forUser(user)
} yield count
Scala Joy = Pattern Matching
Expressive code with decomposition
32
Urn("soundcloud:users:20") match {
case Urn(_, "tracks", _) => None,
case Urn(_, "messages", "20") => None,
case Urn(_, "users", id) => Some(id)
}
Scala Joy = Functional Goodness
Function arguments and references
33
delete("/playlist/:urn/likes")(destroy)
def destroy(request: Request) =
write(request, 200)(repo.deleteLike)
def write
(request: Request, statusCode: Int)
(f: (UserSession, Urn) => Future[Like]) = {
// ...
}
Futures!
Finagle
● Twitter rpc library on top of Netty
● Support for multiple protocols
● Future composition
35
Futures
Instance API (excerpt)
36
class Future[A] {
def get(): A
def map[B](f: A => B): Future[B]
def flatMap[B](f: A => Future[B]]): Future[B]
def onSuccess(f : A => Unit): Future[A]
}
Futures
Object API (excerpt)
37
object Future {
def value[A](a: A): Future[A]
def exception[A](e: Throwable): Future[A]
def collect[A](fs : Seq[Future[A]]): Future[Seq[A]]
}
Futures - Examples
Multiple transformations - The ugly way
38
service.getUsers().flatMap { users =>
service.tracksFor(users).flatMap { tracks =>
asJson(tracks)
}
}.onSuccess(json => log(s"found $json"))
Futures - Example
Multiple transformations - The nice way
39
val response = for {
users <- service.getUsers()
tracks <- service.tracksFor(users)
json <- asJson(tracks)
} yield json
response.onSuccess(json => log(s"found $json"))
Scala Problems
● Implicit conversions
● Binary compatibility of libraries
● Tooling still not perfect
40
SBT
IntelliJ
● Code inspection
● Debugging
● SBT support
42
Chapter 3
The Cutover
Integrate Service
44
Integration Risks
● Service failure
● Data loss after rolling back
● Data loss caused by stale clients
45
Integration Risks
● Service failure → load testing, A/B testing
● Data loss after rolling back
● Data loss caused by stale clients
46
Integration Risks
● Service failure → load testing, A/B testing
● Data loss after rolling back → prepare scripts, practice
● Data loss caused by stale clients
47
Integration Risks
● Service failure → load testing, A/B testing
● Data loss after rolling back → prepare scripts, practice
● Data loss caused by stale clients → keep migration running
48
Enable Feature
49
Retire Old Database
50
Convo
● 500 million requests per day
● 1000 qps during peak time
● 5 instances
51
Microservice Problems
● Event bus dependency
● Maintenance overhead
● Distributed tracing
52
Microservices
→ Not a silver bullet
53
Questions?
Images
● Slide 4,7 - Rails Logo http://en.wikipedia.org/wiki/File:Ruby_on_Rails.svg
● Slide 6,51 - Party Cat http://ghostexist.deviantart.com/art/Party-Cat-logo-287986071
● Silde 7 - MySQL Logo http://blogwifi.fr/?p=9990
● Slide 7 - Hadoop Cop https://svn.apache.org/repos/asf/hadoop/logos/out_rgb/hadoop-security-logo.
jpg
● Slide 10 - Hello, My Name Is: http://commons.wikimedia.org/wiki/File:Hello_my_name_is_sticker.
svg
● Slide 14 - Sad Panda: http://www.whatsupyasieve.com/2012/09/17/lockout-blues/sad-panda-2/
● Slide 16 - Exit Sign: http://logo-kid.com/emergency-exit-sign-left.htm
● Slide 22 - Groovy Logo: http://groovy.codehaus.org/images/groovy-logo-medium.png
● Slide 20, 25, 44 - Book Page: http://daviddiazolivares.deviantart.com/art/Old-Book-Page-
345869530
● Slide 34 - Back to the future: http://i.huffpost.com/gen/1369403/thumbs/o-BACK-TO-THE-FUTURE-
facebook.jpg
● Slide 42 - Tommy Lee Jones: http://persephonemagazine.com/2014/04/friday-news-bites-airline-
pranks-gabriel-garcia-marquez-pulitzers-more/film-title-no-country-for-old-men/
● Slide 55 - That’s all folks: http://www.hd2wallpapers.com/view/thats_all_folks-1280x800.php
56

Weitere ähnliche Inhalte

Was ist angesagt?

Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
Nitin Kumar
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
Karthik .P.R
 

Was ist angesagt? (20)

Reporting Large Environment Zabbix Database
Reporting Large Environment Zabbix DatabaseReporting Large Environment Zabbix Database
Reporting Large Environment Zabbix Database
 
Bitsy graph database
Bitsy graph databaseBitsy graph database
Bitsy graph database
 
Alexander Naydenko - Nagios to Zabbix Migration | ZabConf2016
Alexander Naydenko - Nagios to Zabbix Migration | ZabConf2016Alexander Naydenko - Nagios to Zabbix Migration | ZabConf2016
Alexander Naydenko - Nagios to Zabbix Migration | ZabConf2016
 
Importance of ‘Centralized Event collection’ and BigData platform for Analysis !
Importance of ‘Centralized Event collection’ and BigData platform for Analysis !Importance of ‘Centralized Event collection’ and BigData platform for Analysis !
Importance of ‘Centralized Event collection’ and BigData platform for Analysis !
 
Introducing Venice
Introducing VeniceIntroducing Venice
Introducing Venice
 
Filipe paternot - Case Study: Zabbix Deployment at Globo.com
Filipe paternot - Case Study: Zabbix Deployment at Globo.comFilipe paternot - Case Study: Zabbix Deployment at Globo.com
Filipe paternot - Case Study: Zabbix Deployment at Globo.com
 
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
 
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
 
Apache Kafka at LinkedIn
Apache Kafka at LinkedInApache Kafka at LinkedIn
Apache Kafka at LinkedIn
 
Ambry : Linkedin's Scalable Geo-Distributed Object Store
Ambry : Linkedin's Scalable Geo-Distributed Object StoreAmbry : Linkedin's Scalable Geo-Distributed Object Store
Ambry : Linkedin's Scalable Geo-Distributed Object Store
 
Lessons Learned from Building and Operating Scuba
Lessons Learned from Building and Operating ScubaLessons Learned from Building and Operating Scuba
Lessons Learned from Building and Operating Scuba
 
Scaling MySQL using Fabric
Scaling MySQL using FabricScaling MySQL using Fabric
Scaling MySQL using Fabric
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
 
E2E Data Pipeline - Apache Spark/Airflow/Livy
E2E Data Pipeline - Apache Spark/Airflow/LivyE2E Data Pipeline - Apache Spark/Airflow/Livy
E2E Data Pipeline - Apache Spark/Airflow/Livy
 
Dev309 from asgard to zuul - netflix oss-final
Dev309  from asgard to zuul - netflix oss-finalDev309  from asgard to zuul - netflix oss-final
Dev309 from asgard to zuul - netflix oss-final
 
Microservices with Spring Cloud
Microservices with Spring CloudMicroservices with Spring Cloud
Microservices with Spring Cloud
 
Kafka for begginer
Kafka for begginerKafka for begginer
Kafka for begginer
 
How Kafka and MemSQL Became the Dynamic Duo (Sarung Tripathi, MemSQL) Kafka S...
How Kafka and MemSQL Became the Dynamic Duo (Sarung Tripathi, MemSQL) Kafka S...How Kafka and MemSQL Became the Dynamic Duo (Sarung Tripathi, MemSQL) Kafka S...
How Kafka and MemSQL Became the Dynamic Duo (Sarung Tripathi, MemSQL) Kafka S...
 
Евгений Напрягло ".NET Framework Hosting API Overview"
Евгений Напрягло ".NET Framework Hosting API Overview"Евгений Напрягло ".NET Framework Hosting API Overview"
Евгений Напрягло ".NET Framework Hosting API Overview"
 
Mistral Hong Kong Unconference track
Mistral Hong Kong Unconference trackMistral Hong Kong Unconference track
Mistral Hong Kong Unconference track
 

Andere mochten auch

Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
Embracing the Monolith in Small Teams: Doubling down on python to move fast w...Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
PyData
 

Andere mochten auch (20)

Dismantling the Monolith: Scaling with Microservices
Dismantling the Monolith: Scaling with MicroservicesDismantling the Monolith: Scaling with Microservices
Dismantling the Monolith: Scaling with Microservices
 
Rubyslava beyond the_monolith
Rubyslava beyond the_monolithRubyslava beyond the_monolith
Rubyslava beyond the_monolith
 
Disassembling the Monolith: Taming Large Software Projects with Node.js
Disassembling the Monolith: Taming Large Software Projects with Node.jsDisassembling the Monolith: Taming Large Software Projects with Node.js
Disassembling the Monolith: Taming Large Software Projects with Node.js
 
Monolith vs Microservices vs Teams
Monolith vs Microservices vs TeamsMonolith vs Microservices vs Teams
Monolith vs Microservices vs Teams
 
JFokus 2015 - Hacking the-monolith
JFokus 2015 - Hacking the-monolithJFokus 2015 - Hacking the-monolith
JFokus 2015 - Hacking the-monolith
 
Splitting the Monolith
Splitting the MonolithSplitting the Monolith
Splitting the Monolith
 
Breaking Down the Monolith - Peter Marton, RisingStack
Breaking Down the Monolith - Peter Marton, RisingStackBreaking Down the Monolith - Peter Marton, RisingStack
Breaking Down the Monolith - Peter Marton, RisingStack
 
Breaking the monolith at jobandtalent - AWS Summit Barcelona 2015
Breaking the monolith at jobandtalent - AWS Summit Barcelona 2015Breaking the monolith at jobandtalent - AWS Summit Barcelona 2015
Breaking the monolith at jobandtalent - AWS Summit Barcelona 2015
 
My Monolith is Melting - PIPELINE CONF 2015
My Monolith is Melting - PIPELINE CONF 2015My Monolith is Melting - PIPELINE CONF 2015
My Monolith is Melting - PIPELINE CONF 2015
 
Monolith to Microservices - O’Reilly Oscon
Monolith to Microservices - O’Reilly OsconMonolith to Microservices - O’Reilly Oscon
Monolith to Microservices - O’Reilly Oscon
 
Evolving toward Microservices - O’Reilly SACON Keynote
Evolving toward Microservices  - O’Reilly SACON KeynoteEvolving toward Microservices  - O’Reilly SACON Keynote
Evolving toward Microservices - O’Reilly SACON Keynote
 
DPM UK: Stealing Project Management Lessons from Artificial Intelligence
DPM UK: Stealing Project Management Lessons from Artificial IntelligenceDPM UK: Stealing Project Management Lessons from Artificial Intelligence
DPM UK: Stealing Project Management Lessons from Artificial Intelligence
 
I-Tier: Breaking Up the Monolith @ Philly ETE
I-Tier: Breaking Up the Monolith @ Philly ETEI-Tier: Breaking Up the Monolith @ Philly ETE
I-Tier: Breaking Up the Monolith @ Philly ETE
 
Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
Embracing the Monolith in Small Teams: Doubling down on python to move fast w...Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
Embracing the Monolith in Small Teams: Doubling down on python to move fast w...
 
Surviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
Surviving as a Monolith in a Microservices World - by Blair Olynyk, HyperwalletSurviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
Surviving as a Monolith in a Microservices World - by Blair Olynyk, Hyperwallet
 
(PFC304) Effective Interprocess Communications in the Cloud: The Pros and Con...
(PFC304) Effective Interprocess Communications in the Cloud: The Pros and Con...(PFC304) Effective Interprocess Communications in the Cloud: The Pros and Con...
(PFC304) Effective Interprocess Communications in the Cloud: The Pros and Con...
 
From the Monolith to Microservices - CraftConf 2015
From the Monolith to Microservices - CraftConf 2015From the Monolith to Microservices - CraftConf 2015
From the Monolith to Microservices - CraftConf 2015
 
MicroserviceArchitecture in detail over Monolith.
MicroserviceArchitecture in detail over Monolith.MicroserviceArchitecture in detail over Monolith.
MicroserviceArchitecture in detail over Monolith.
 
Pragmatic Microservices
Pragmatic MicroservicesPragmatic Microservices
Pragmatic Microservices
 
The Journey from Monolith to Microservices: a Guided Adventure
The Journey from Monolith to Microservices: a Guided AdventureThe Journey from Monolith to Microservices: a Guided Adventure
The Journey from Monolith to Microservices: a Guided Adventure
 

Ähnlich wie Breaking the Monolith - Microservice Extraction at SoundCloud

2010 12 mysql_clusteroverview
2010 12 mysql_clusteroverview2010 12 mysql_clusteroverview
2010 12 mysql_clusteroverview
Dimas Prasetyo
 
Session 3 - CloudStack Test Automation and CI
Session 3 - CloudStack Test Automation and CISession 3 - CloudStack Test Automation and CI
Session 3 - CloudStack Test Automation and CI
tcloudcomputing-tw
 

Ähnlich wie Breaking the Monolith - Microservice Extraction at SoundCloud (20)

Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Micheal Pershyn "Coljure 4 Big Data"
Micheal Pershyn "Coljure 4 Big Data"Micheal Pershyn "Coljure 4 Big Data"
Micheal Pershyn "Coljure 4 Big Data"
 
High-Availability using MySQL Fabric
High-Availability using MySQL FabricHigh-Availability using MySQL Fabric
High-Availability using MySQL Fabric
 
MySQL 5.6 Replication Webinar
MySQL 5.6 Replication WebinarMySQL 5.6 Replication Webinar
MySQL 5.6 Replication Webinar
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
Automating using Ansible
Automating using AnsibleAutomating using Ansible
Automating using Ansible
 
Percona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBAPercona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBA
 
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius SchumacherOSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
 
MySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated EnvironmentMySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated Environment
 
From swarm to swam-mode in the CERN container service
From swarm to swam-mode in the CERN container serviceFrom swarm to swam-mode in the CERN container service
From swarm to swam-mode in the CERN container service
 
Varnish - PLNOG 4
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4
 
How Opera Syncs Tens of Millions of Browsers and Sleeps Well at Night
How Opera Syncs Tens of Millions of Browsers and Sleeps Well at NightHow Opera Syncs Tens of Millions of Browsers and Sleeps Well at Night
How Opera Syncs Tens of Millions of Browsers and Sleeps Well at Night
 
2010 12 mysql_clusteroverview
2010 12 mysql_clusteroverview2010 12 mysql_clusteroverview
2010 12 mysql_clusteroverview
 
Full Automated Continuous Integration and Testing Infrastructure for Maxscale...
Full Automated Continuous Integration and Testing Infrastructure for Maxscale...Full Automated Continuous Integration and Testing Infrastructure for Maxscale...
Full Automated Continuous Integration and Testing Infrastructure for Maxscale...
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
Session 3 - CloudStack Test Automation and CI
Session 3 - CloudStack Test Automation and CISession 3 - CloudStack Test Automation and CI
Session 3 - CloudStack Test Automation and CI
 
Massaging the Pony: Message Queues and You
Massaging the Pony: Message Queues and YouMassaging the Pony: Message Queues and You
Massaging the Pony: Message Queues and You
 
Midwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL FeaturesMidwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL Features
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
 

Kürzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Breaking the Monolith - Microservice Extraction at SoundCloud

  • 1. Breaking the Monolith Microservice Extraction at SoundCloud
  • 2. Soundcloud ● 11 hours uploaded every minute ● 150 million tracks ● 300 million users 2
  • 3. History ● Rails 2.3 ● MySQL ● S3 3
  • 6. History ● Rails 2.3 ● MySQL ● AWS ● Cassandra ● Hadoop ● SolR ● RabbitMQ https://developers.soundcloud.com/blog/evolution-of-soundclouds-architecture 6
  • 7. Still not enough ● More servers ● Add caching layer ● Defer long running tasks to workers 7
  • 8. Still not enough ● Optimize database schema ● Introduce read slaves ● Dedicated databases for some models 8
  • 10. Major pain points ● Testing, building and deploying ● Dependency hell ● “I’d rather not touch this” 10
  • 11. Rails problems I - No service layer 11 <% Category.all.each do |cat| %> <li><%= cat.name %></li> <% end %>
  • 12. Rails problems I - No service layer ⇒ Tight coupling with storage layer! 12 <% Category.all.each do |cat| %> <li><%= cat.name %></li> <% end %>
  • 13. Rails problems II - Active Record Magic 13 class User < ActiveRecord::Base validates_length_of :username, :within => 2..64 before_save :encrypt_password, :accept_terms_of_use has_many :comments, :dependent => :destroy # ... end
  • 14. Rails problems II - Active Record Magic ⇒ Easy to write, hard to maintain 14 class User < ActiveRecord::Base validates_length_of :username, :within => 2..64 before_save :encrypt_password, :accept_terms_of_use has_many :comments, :dependent => :destroy # ... end
  • 15. Ruby Problems ● GIL ● Native extensions ● Dependency management can be painful 15
  • 16.
  • 17. Extract features as Services ● Less painful to maintain ● Easy to replace ● Fun to build 17
  • 18. An Example: Messages ● 200 million messages ● MySQL database on shared host ● Features: ○ embedded sounds ○ email notifications ○ spam detection 18
  • 19. Migration Requirements ● New schema to support upcoming features ● Dedicated database ● Zero downtime 19
  • 23. Migrating the Schema Convenient Dependency Management with @Grapes 23 #!/usr/bin/env groovy @Grapes([ @Grab(group='org.yaml', module='snakeyaml', version='1.12'), @Grab(group='mysql', module='mysql-connector-java', version='5.1.24') ]) import groovy.sql.Sql import org.yaml.snakeyaml.Yaml
  • 24. Strategy ● Import all messages ● Setup cron job to get new messages ● Listen to events for updates 24
  • 26. Creating a new service 26
  • 27. Convo ● Scala ● Twitter Finagle ● Scalatra Framework 27
  • 29. Scala ● Functional ● OOP ● Static but inferred typing 29
  • 30. Scala Joy = Options I Good bye NullPointerException 30 val opt: Option[String] = params.get("id") val id: Int = opt.map(id => id.toInt).getOrElse(10)
  • 31. Scala Joy = Options II Safe chaining with for comprehensions 31 for { id <- params.get("id") user <- users.lookup(id) count <- counts.forUser(user) } yield count
  • 32. Scala Joy = Pattern Matching Expressive code with decomposition 32 Urn("soundcloud:users:20") match { case Urn(_, "tracks", _) => None, case Urn(_, "messages", "20") => None, case Urn(_, "users", id) => Some(id) }
  • 33. Scala Joy = Functional Goodness Function arguments and references 33 delete("/playlist/:urn/likes")(destroy) def destroy(request: Request) = write(request, 200)(repo.deleteLike) def write (request: Request, statusCode: Int) (f: (UserSession, Urn) => Future[Like]) = { // ... }
  • 35. Finagle ● Twitter rpc library on top of Netty ● Support for multiple protocols ● Future composition 35
  • 36. Futures Instance API (excerpt) 36 class Future[A] { def get(): A def map[B](f: A => B): Future[B] def flatMap[B](f: A => Future[B]]): Future[B] def onSuccess(f : A => Unit): Future[A] }
  • 37. Futures Object API (excerpt) 37 object Future { def value[A](a: A): Future[A] def exception[A](e: Throwable): Future[A] def collect[A](fs : Seq[Future[A]]): Future[Seq[A]] }
  • 38. Futures - Examples Multiple transformations - The ugly way 38 service.getUsers().flatMap { users => service.tracksFor(users).flatMap { tracks => asJson(tracks) } }.onSuccess(json => log(s"found $json"))
  • 39. Futures - Example Multiple transformations - The nice way 39 val response = for { users <- service.getUsers() tracks <- service.tracksFor(users) json <- asJson(tracks) } yield json response.onSuccess(json => log(s"found $json"))
  • 40. Scala Problems ● Implicit conversions ● Binary compatibility of libraries ● Tooling still not perfect 40
  • 41. SBT
  • 42. IntelliJ ● Code inspection ● Debugging ● SBT support 42
  • 45. Integration Risks ● Service failure ● Data loss after rolling back ● Data loss caused by stale clients 45
  • 46. Integration Risks ● Service failure → load testing, A/B testing ● Data loss after rolling back ● Data loss caused by stale clients 46
  • 47. Integration Risks ● Service failure → load testing, A/B testing ● Data loss after rolling back → prepare scripts, practice ● Data loss caused by stale clients 47
  • 48. Integration Risks ● Service failure → load testing, A/B testing ● Data loss after rolling back → prepare scripts, practice ● Data loss caused by stale clients → keep migration running 48
  • 51. Convo ● 500 million requests per day ● 1000 qps during peak time ● 5 instances 51
  • 52. Microservice Problems ● Event bus dependency ● Maintenance overhead ● Distributed tracing 52
  • 53. Microservices → Not a silver bullet 53
  • 54.
  • 56. Images ● Slide 4,7 - Rails Logo http://en.wikipedia.org/wiki/File:Ruby_on_Rails.svg ● Slide 6,51 - Party Cat http://ghostexist.deviantart.com/art/Party-Cat-logo-287986071 ● Silde 7 - MySQL Logo http://blogwifi.fr/?p=9990 ● Slide 7 - Hadoop Cop https://svn.apache.org/repos/asf/hadoop/logos/out_rgb/hadoop-security-logo. jpg ● Slide 10 - Hello, My Name Is: http://commons.wikimedia.org/wiki/File:Hello_my_name_is_sticker. svg ● Slide 14 - Sad Panda: http://www.whatsupyasieve.com/2012/09/17/lockout-blues/sad-panda-2/ ● Slide 16 - Exit Sign: http://logo-kid.com/emergency-exit-sign-left.htm ● Slide 22 - Groovy Logo: http://groovy.codehaus.org/images/groovy-logo-medium.png ● Slide 20, 25, 44 - Book Page: http://daviddiazolivares.deviantart.com/art/Old-Book-Page- 345869530 ● Slide 34 - Back to the future: http://i.huffpost.com/gen/1369403/thumbs/o-BACK-TO-THE-FUTURE- facebook.jpg ● Slide 42 - Tommy Lee Jones: http://persephonemagazine.com/2014/04/friday-news-bites-airline- pranks-gabriel-garcia-marquez-pulitzers-more/film-title-no-country-for-old-men/ ● Slide 55 - That’s all folks: http://www.hd2wallpapers.com/view/thats_all_folks-1280x800.php 56