Finagle By Twitter Engineer @ Knoldus

21
Introduction to Finagle @

description

Introduction to Finagle

Transcript of Finagle By Twitter Engineer @ Knoldus

Page 1: Finagle By Twitter Engineer @ Knoldus

Introduction to Finagle

@

Page 2: Finagle By Twitter Engineer @ Knoldus

[email protected]

Core Services - Platform Engineering

Page 3: Finagle By Twitter Engineer @ Knoldus

In the beginning ...

Page 4: Finagle By Twitter Engineer @ Knoldus
Page 5: Finagle By Twitter Engineer @ Knoldus
Page 6: Finagle By Twitter Engineer @ Knoldus
Page 7: Finagle By Twitter Engineer @ Knoldus

A brave new world ...

TypesafeExpressivePerformant

(thank you JVM)...

Page 8: Finagle By Twitter Engineer @ Knoldus

Futures

Page 9: Finagle By Twitter Engineer @ Knoldus

Synchronous Futures

def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int]

println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println

Page 10: Finagle By Twitter Engineer @ Knoldus

Synchronous Futures

Page 11: Finagle By Twitter Engineer @ Knoldus

Synchronous Futuresdef 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

Page 12: Finagle By Twitter Engineer @ Knoldus
Page 13: Finagle By Twitter Engineer @ Knoldus

Address resolution

TCP handshake

Serialization => Deserialization

the networking glue ...

Page 14: Finagle By Twitter Engineer @ Knoldus

: Request => Future [ Response ]

Page 15: Finagle By Twitter Engineer @ Knoldus

trait UserService {def getByUserId( userId : Long ) : Future [ User ]def getByScreenName( screenName: String ) : Future [ User ]

}

trait TweetService {def findByUserId( userId : Long ) : Future [ Seq[ Tweet ] ]

}

Page 16: Finagle By Twitter Engineer @ Knoldus

trait UserTweetService {val userService : UserServiceval tweetService : TweetService

def findUserAndTweets(userId : Long

) : Future [ ( User, Seq[Tweet] ) ] = Future.join (

userService.findByUserId( userId ), tweetService.findByUserId( userId )

)

}}

1

2 3 2 3

4

Page 17: Finagle By Twitter Engineer @ Knoldus

trait ScreenNameTweetService {val userService : UserServiceval tweetService : TweetService

def findByScreenName(screenName: String

) : Future [ Seq[Tweet] ] = {

userService.findByScreenName( screenName ) flatMap {user => tweetService.findByUserId( user.id )

}

}}

1

2 3 4 5

6

Page 18: Finagle By Twitter Engineer @ Knoldus

other benefits ...

Page 19: Finagle By Twitter Engineer @ Knoldus

val someService = Http.client(“inet!google.com:80”)

val anotherService =Http.client(

“zk!myzkhost.mycompany.com:2181!/my/zk/path”)

Address Resolution

Page 20: Finagle By Twitter Engineer @ Knoldus

Source Load Balancing

vs

Page 21: Finagle By Twitter Engineer @ Knoldus

Thanks!

twitter.github.io/finagle@finagle@pzdk