SlideShare a Scribd company logo
@ 
Introduction to Finagle
puneet@twitter.com 
Core Services - Platform Engineering
In the beginning ...
Finagle By Twitter Engineer @ Knoldus
Finagle By Twitter Engineer @ Knoldus
Finagle By Twitter Engineer @ Knoldus
A brave new world ... 
Typesafe 
Expressive 
Performant 
(thank you JVM) 
...
Futures
Synchronous Futures 
def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int] 
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
Synchronous Futures
Synchronous Futures 
def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int] 
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println 
println ( piDigit ( 100 ) * 10 ) ) piDigit ( 100 ) map { _ * 10 } onSuccess println 
println ( piDigit ( piDigit ( 100 ) ) ) piDigit ( 100 ) flatMap piDigit onSuccess println 
println ( ( 0 to 100 ) map piDigit ) Future.collect { 
( 0 to 100 ) map piDigit 
} onSuccess println
Finagle By Twitter Engineer @ Knoldus
the networking glue ... 
Address resolution 
TCP handshake 
Serialization => Deserialization
: Request => Future [ Response ]
trait UserService { 
def getByUserId( userId : Long ) : Future [ User ] 
def getByScreenName( screenName: String ) : Future [ User ] 
} 
trait TweetService { 
def findByUserId( userId : Long ) : Future [ Seq[ Tweet ] ] 
}
trait UserTweetService { 
val userService : UserService 
val tweetService : TweetService 
def findUserAndTweets( 
userId : Long 
) : Future [ ( User, Seq[Tweet] ) ] = 
Future.join ( 
userService.findByUserId( userId ), 
tweetService.findByUserId( userId ) 
) 
} 
} 
1 
4 
2 3 2 3
trait ScreenNameTweetService { 
val userService : UserService 
val tweetService : TweetService 
def findByScreenName( 
screenName: String 
) : Future [ Seq[Tweet] ] = { 
userService.findByScreenName( screenName ) flatMap { 
user => tweetService.findByUserId( user.id ) 
} 
} 
} 
1 
6 
2 3 4 5
other benefits ...
val someService = Http.client(“inet!google.com:80”) 
val anotherService = 
Http.client( 
“zk!myzkhost.mycompany.com:2181!/my/zk/path��� 
) 
Address Resolution
Source Load Balancing 
vs
Thanks! 
twitter.github.io/finagle 
@finagle 
@pzdk

More Related Content

Finagle By Twitter Engineer @ Knoldus

  • 2. puneet@twitter.com Core Services - Platform Engineering
  • 7. A brave new world ... Typesafe Expressive Performant (thank you JVM) ...
  • 9. Synchronous Futures def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int] println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
  • 11. Synchronous Futures def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int] println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println println ( piDigit ( 100 ) * 10 ) ) piDigit ( 100 ) map { _ * 10 } onSuccess println println ( piDigit ( piDigit ( 100 ) ) ) piDigit ( 100 ) flatMap piDigit onSuccess println println ( ( 0 to 100 ) map piDigit ) Future.collect { ( 0 to 100 ) map piDigit } onSuccess println
  • 13. the networking glue ... Address resolution TCP handshake Serialization => Deserialization
  • 14. : Request => Future [ Response ]
  • 15. trait UserService { def getByUserId( userId : Long ) : Future [ User ] def getByScreenName( screenName: String ) : Future [ User ] } trait TweetService { def findByUserId( userId : Long ) : Future [ Seq[ Tweet ] ] }
  • 16. trait UserTweetService { val userService : UserService val tweetService : TweetService def findUserAndTweets( userId : Long ) : Future [ ( User, Seq[Tweet] ) ] = Future.join ( userService.findByUserId( userId ), tweetService.findByUserId( userId ) ) } } 1 4 2 3 2 3
  • 17. trait ScreenNameTweetService { val userService : UserService val tweetService : TweetService def findByScreenName( screenName: String ) : Future [ Seq[Tweet] ] = { userService.findByScreenName( screenName ) flatMap { user => tweetService.findByUserId( user.id ) } } } 1 6 2 3 4 5
  • 19. val someService = Http.client(“inet!google.com:80”) val anotherService = Http.client( “zk!myzkhost.mycompany.com:2181!/my/zk/path” ) Address Resolution