SlideShare a Scribd company logo
Sharding and Load Balancing in Scala
Twitter's Finagle
Geoff Ballinger
Technical Advisor at Mobile Acuity Ltd.
• some ML and Lisp in the early 90s
• C, C++ and Java since – embedded and server
• apps on BB, Android and iOS
• Mobile
• Startups
• Scaling
• Integration
• Deployment & Ops
>>> Background
>>> Finagle
https://blog.twitter.com/2011/finagl
e-protocol-agnostic-rpc-system
• Finagle is an extensible RPC system for Scala
• Protocol-agnostic and asynchronous
• Created, used and published by Twitter
• Built on netty and thus NIO
• Heavy use of Futures etc
• http://twitter.github.io/finagle/
• Multiple HTTP workers – part of the result
• Each shard is one or more identical workers
• Sharder scatters requests to the shards and
gathers the results
• Load balance between workers
• Fault tolerant
• Chance to play w/ Scala in anger!
• (Simple rational reconstruction)
>>> A simple sharder?
object Worker extends App {
try {
// Collect args
val port = Integer.parseInt(args(0))
val value = args(1)
// Define our service - just return the value provided!
val service = new Service[HttpRequest, HttpResponse] {
def apply(req: HttpRequest) = {
val buffer = ChannelBuffers.copiedBuffer(value, Charset.forName("UTF-8"))
val response = new DefaultHttpResponse(req.getProtocolVersion, HttpResponseStatus.OK)
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain")
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes())
response.setContent(buffer)
Future.value(response)
}
}
>>> Worker (1)
// Run this worker over the required port
val server = ServerBuilder()
.codec(Http())
.bindTo(new InetSocketAddress(port))
.name("Shard")
.build(service)
} catch {
case t: Throwable => {
System.err.println(t.getMessage())
System.err.println("Usage: Worker <port> <value>")
}
}
}
>>> Worker (2)
// Collect port arg
val port = Integer.parseInt(args(0))
// Build up shards from host specs on remaining command line
val shards = args.tail.map(spec => {
ClientBuilder()
.codec(Http())
.hosts(spec)
.hostConnectionLimit(10)
.retryPolicy(policy)
.build()
})
>>> Sharder (setup)
// Define our service - scatter to the shards and gather the results
val service = new Service[HttpRequest, HttpResponse] {
def apply(req: HttpRequest) = {
Future.collect(shards.map(shard => { // Scatter
shard(req).map(resp => resp.getContent().toString(CHARSET))
}))
.map(resps => { // Gather
val bf = ChannelBuffers.copiedBuffer(resps.reduceLeft(_+":"+_), CHARSET)
val resp = new DefaultHttpResponse(req.getProtocolVersion, HttpResponseStatus.OK)
resp.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain")
resp.setHeader(HttpHeaders.Names.CONTENT_LENGTH, bf.readableBytes())
resp.setContent(bf)
resp
})
}
}
>>> Sharder (service)
>>> Demo time!
>>> Reflections and Opinions
• Concise and expressive
• Shoulders of giants
• Poorly documented
• Exposes too many lower APIs
• Twitter vs Scala vs Akka Futures!
https://github.com/geoffballinger/simple-sharder
geoff@geoffballinger.co.uk
@geoffballinger
http://www.geoffballinger.co.uk
>>> Thanks for Listening!

More Related Content

What's hot

Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices
💡 Tomasz Kogut
 
Flamingo Training - Hello World
Flamingo Training - Hello WorldFlamingo Training - Hello World
Flamingo Training - Hello World
i-love-flamingo
 
Flamingo Core Concepts
Flamingo Core ConceptsFlamingo Core Concepts
Flamingo Core Concepts
i-love-flamingo
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
t k
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
Thomas Roch
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
Konrad Malawski
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
async_io
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
cacois
 
Consul presentation
Consul presentationConsul presentation
Consul presentation
Vladimir Kosmala
 
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Samir Bessalah
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
Nir Kaufman
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Nikolas Burk
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
Babacar NIANG
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
Robert F. Dickerson
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
Bo-Young Park
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
Bo-Young Park
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
Tomasz Kowalczewski
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
CocoaHeads France
 
Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams
Seiya Mizuno
 

What's hot (20)

Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices
 
Flamingo Training - Hello World
Flamingo Training - Hello WorldFlamingo Training - Hello World
Flamingo Training - Hello World
 
Flamingo Core Concepts
Flamingo Core ConceptsFlamingo Core Concepts
Flamingo Core Concepts
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Consul presentation
Consul presentationConsul presentation
Consul presentation
 
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
 
Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams
 

Similar to Sharding and Load Balancing in Scala - Twitter's Finagle

Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTP
datamantra
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
Haci Murat Yaman
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
Yiguang Hu
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
Oleg Podsechin
 
Finagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvmFinagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvm
PrasannaKumar Sathyanarayanan
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
Tim Burks
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
Oleg Podsechin
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
JavaEE Trainers
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
Rubyc Slides
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationNordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 

Similar to Sharding and Load Balancing in Scala - Twitter's Finagle (20)

Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTP
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Finagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvmFinagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvm
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationNordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API Documentation
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 

More from Geoff Ballinger

Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
Geoff Ballinger
 
The Internet Of (very big) Things
The Internet Of (very big) ThingsThe Internet Of (very big) Things
The Internet Of (very big) Things
Geoff Ballinger
 
Docker in Embedded Systems
Docker in Embedded SystemsDocker in Embedded Systems
Docker in Embedded Systems
Geoff Ballinger
 
The Load Balancer: War Stories with HAProxy
The Load Balancer: War Stories with HAProxyThe Load Balancer: War Stories with HAProxy
The Load Balancer: War Stories with HAProxy
Geoff Ballinger
 
The Power of Conversation
The Power of ConversationThe Power of Conversation
The Power of Conversation
Geoff Ballinger
 
Mobile in 2016?
Mobile in 2016?Mobile in 2016?
Mobile in 2016?
Geoff Ballinger
 
The Buzz from Barcelona: MWC16
The Buzz from Barcelona: MWC16The Buzz from Barcelona: MWC16
The Buzz from Barcelona: MWC16
Geoff Ballinger
 
MoMoGPW: IoT's turn for the Kool-Aid?
MoMoGPW: IoT's turn for the Kool-Aid?MoMoGPW: IoT's turn for the Kool-Aid?
MoMoGPW: IoT's turn for the Kool-Aid?
Geoff Ballinger
 
The “other side” of MWC: IoT’s turn for the Kool-Aid?
The “other side” of MWC: IoT’s turn for the Kool-Aid?The “other side” of MWC: IoT’s turn for the Kool-Aid?
The “other side” of MWC: IoT’s turn for the Kool-Aid?
Geoff Ballinger
 
MVP: Minimum Viable apP?
MVP: Minimum Viable apP?MVP: Minimum Viable apP?
MVP: Minimum Viable apP?
Geoff Ballinger
 
Mobile as an Entrepreneurial Opportunity
Mobile as an Entrepreneurial OpportunityMobile as an Entrepreneurial Opportunity
Mobile as an Entrepreneurial Opportunity
Geoff Ballinger
 
Mobile Platforms Redux
Mobile Platforms ReduxMobile Platforms Redux
Mobile Platforms Redux
Geoff Ballinger
 
Connecting the real world with your mobile - or how to ask "What's that?"
Connecting the real world with your mobile - or how to ask "What's that?"Connecting the real world with your mobile - or how to ask "What's that?"
Connecting the real world with your mobile - or how to ask "What's that?"
Geoff Ballinger
 
Barcamp Glasgow 2010 - Mobile
Barcamp Glasgow 2010 - MobileBarcamp Glasgow 2010 - Mobile
Barcamp Glasgow 2010 - Mobile
Geoff Ballinger
 
MWC2010 Overview
MWC2010 OverviewMWC2010 Overview
MWC2010 Overview
Geoff Ballinger
 
Visual Interactivity
Visual InteractivityVisual Interactivity
Visual Interactivity
Geoff Ballinger
 
BarCampScotland: What Is Visual Interactivity?
BarCampScotland: What Is Visual Interactivity?BarCampScotland: What Is Visual Interactivity?
BarCampScotland: What Is Visual Interactivity?
Geoff Ballinger
 

More from Geoff Ballinger (17)

Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
Highly Accurate Alignment of Data from Measurement Trains:

 the Challenges o...
 
The Internet Of (very big) Things
The Internet Of (very big) ThingsThe Internet Of (very big) Things
The Internet Of (very big) Things
 
Docker in Embedded Systems
Docker in Embedded SystemsDocker in Embedded Systems
Docker in Embedded Systems
 
The Load Balancer: War Stories with HAProxy
The Load Balancer: War Stories with HAProxyThe Load Balancer: War Stories with HAProxy
The Load Balancer: War Stories with HAProxy
 
The Power of Conversation
The Power of ConversationThe Power of Conversation
The Power of Conversation
 
Mobile in 2016?
Mobile in 2016?Mobile in 2016?
Mobile in 2016?
 
The Buzz from Barcelona: MWC16
The Buzz from Barcelona: MWC16The Buzz from Barcelona: MWC16
The Buzz from Barcelona: MWC16
 
MoMoGPW: IoT's turn for the Kool-Aid?
MoMoGPW: IoT's turn for the Kool-Aid?MoMoGPW: IoT's turn for the Kool-Aid?
MoMoGPW: IoT's turn for the Kool-Aid?
 
The “other side” of MWC: IoT’s turn for the Kool-Aid?
The “other side” of MWC: IoT’s turn for the Kool-Aid?The “other side” of MWC: IoT’s turn for the Kool-Aid?
The “other side” of MWC: IoT’s turn for the Kool-Aid?
 
MVP: Minimum Viable apP?
MVP: Minimum Viable apP?MVP: Minimum Viable apP?
MVP: Minimum Viable apP?
 
Mobile as an Entrepreneurial Opportunity
Mobile as an Entrepreneurial OpportunityMobile as an Entrepreneurial Opportunity
Mobile as an Entrepreneurial Opportunity
 
Mobile Platforms Redux
Mobile Platforms ReduxMobile Platforms Redux
Mobile Platforms Redux
 
Connecting the real world with your mobile - or how to ask "What's that?"
Connecting the real world with your mobile - or how to ask "What's that?"Connecting the real world with your mobile - or how to ask "What's that?"
Connecting the real world with your mobile - or how to ask "What's that?"
 
Barcamp Glasgow 2010 - Mobile
Barcamp Glasgow 2010 - MobileBarcamp Glasgow 2010 - Mobile
Barcamp Glasgow 2010 - Mobile
 
MWC2010 Overview
MWC2010 OverviewMWC2010 Overview
MWC2010 Overview
 
Visual Interactivity
Visual InteractivityVisual Interactivity
Visual Interactivity
 
BarCampScotland: What Is Visual Interactivity?
BarCampScotland: What Is Visual Interactivity?BarCampScotland: What Is Visual Interactivity?
BarCampScotland: What Is Visual Interactivity?
 

Recently uploaded

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 

Recently uploaded (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 

Sharding and Load Balancing in Scala - Twitter's Finagle

  • 1. Sharding and Load Balancing in Scala Twitter's Finagle Geoff Ballinger Technical Advisor at Mobile Acuity Ltd.
  • 2. • some ML and Lisp in the early 90s • C, C++ and Java since – embedded and server • apps on BB, Android and iOS • Mobile • Startups • Scaling • Integration • Deployment & Ops >>> Background
  • 3. >>> Finagle https://blog.twitter.com/2011/finagl e-protocol-agnostic-rpc-system • Finagle is an extensible RPC system for Scala • Protocol-agnostic and asynchronous • Created, used and published by Twitter • Built on netty and thus NIO • Heavy use of Futures etc • http://twitter.github.io/finagle/
  • 4. • Multiple HTTP workers – part of the result • Each shard is one or more identical workers • Sharder scatters requests to the shards and gathers the results • Load balance between workers • Fault tolerant • Chance to play w/ Scala in anger! • (Simple rational reconstruction) >>> A simple sharder?
  • 5. object Worker extends App { try { // Collect args val port = Integer.parseInt(args(0)) val value = args(1) // Define our service - just return the value provided! val service = new Service[HttpRequest, HttpResponse] { def apply(req: HttpRequest) = { val buffer = ChannelBuffers.copiedBuffer(value, Charset.forName("UTF-8")) val response = new DefaultHttpResponse(req.getProtocolVersion, HttpResponseStatus.OK) response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain") response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes()) response.setContent(buffer) Future.value(response) } } >>> Worker (1)
  • 6. // Run this worker over the required port val server = ServerBuilder() .codec(Http()) .bindTo(new InetSocketAddress(port)) .name("Shard") .build(service) } catch { case t: Throwable => { System.err.println(t.getMessage()) System.err.println("Usage: Worker <port> <value>") } } } >>> Worker (2)
  • 7. // Collect port arg val port = Integer.parseInt(args(0)) // Build up shards from host specs on remaining command line val shards = args.tail.map(spec => { ClientBuilder() .codec(Http()) .hosts(spec) .hostConnectionLimit(10) .retryPolicy(policy) .build() }) >>> Sharder (setup)
  • 8. // Define our service - scatter to the shards and gather the results val service = new Service[HttpRequest, HttpResponse] { def apply(req: HttpRequest) = { Future.collect(shards.map(shard => { // Scatter shard(req).map(resp => resp.getContent().toString(CHARSET)) })) .map(resps => { // Gather val bf = ChannelBuffers.copiedBuffer(resps.reduceLeft(_+":"+_), CHARSET) val resp = new DefaultHttpResponse(req.getProtocolVersion, HttpResponseStatus.OK) resp.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain") resp.setHeader(HttpHeaders.Names.CONTENT_LENGTH, bf.readableBytes()) resp.setContent(bf) resp }) } } >>> Sharder (service)
  • 10. >>> Reflections and Opinions • Concise and expressive • Shoulders of giants • Poorly documented • Exposes too many lower APIs • Twitter vs Scala vs Akka Futures!