This document summarizes a presentation about Finagle, a framework developed by Twitter for building reliable services. It discusses how Finagle uses asynchronous Futures and composable Filters and Services to provide high performance RPC. It also covers key Finagle concepts like load balancing, failure handling, and how it is used by many large companies for building distributed systems. The document provides code examples of defining Services and applying Filters in Finagle and Scala.
2. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
RPC Redux
• Control of clients and servers
• Need for predictable performance
• Communication between different languages
• Isolated computations
• Fan out, Fan In distributed systems
• ...
13. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Futures
• Concurrency primitive in Finagle
• Different from scala.concurrent.Future and
java.util.concurrent.Future
• Less context-switching, easier cancelability
• From com.twitter.util.Future
• Composables
• Error and Exception Handling
21. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Filters
val myTimeoutFilter =
new TimeoutFilter[String, Int](1.second,DefaultTimer.twitter)
val myService = new DummyService
val server = myTimeOutFilter andThen myService
22. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Filters
val myTimeoutFilter =
new TimeoutFilter[String,Int](
1.second, DefaultTimer.twitter)
val myService = new DummyService
val service = myService andThen myTimeOutFilter
val server = Httpx.serve( “:8080”, service)
Await.ready(server)
25. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Clients
Finagle client are just full stack services
val myClient: Service[Request, Response] =
Httpx.newService("rtb-bidder.com:8081")
val bidder = Httpx.serve(":8080", myClient)
31. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Service discovery
• Finagle ServerSets via ”Names”
• Uses Zookeeper as Name server
val client = Http.newService(
“zk!myzkhost.home.com:2181!/my/zk/path” )
32. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Twitter-Server
• Template for servers at Twitter built on top of Finagle
• Flags for configuration
• Logging and Metrics
• Admin HTTP UI
• Lifecycle management endpoints, handy for Docker and/or Mesos
• Tracing via ZipKin
34. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Finatra
• Library to easily build API Services on top of the Twitter Stack (Finagle,
Twitter-Server, Twitter-util, etc.)
• Supports Http and Thrift services
• Brings Sinatra like Style to Finagle for Rest Services
37. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
● Thin layer of purely functional basic blocks, to build
composable REST APIs.
● Built on top of Finagle
● Functional wrapper of Finagle-http
● Performance close to Bare Metal Finagle
http://github.com/finagle/finch
38. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Zipkin
• Zipkin is a distributed tracing system that helps us gather timing data
for all the disparate services at Twitter. It manages both the collection
and lookup of this data through a Collector and a Query service.
• Implementation of Google’s Dapper paper
• Moved to OpenZipkin
40. @YourTwitterHandle#Devoxx #YourTag @samklr#devoxx #finagle #scala
Finagle : Cons
• Stuck to old versions of Netty. Currently Netty 3 and now moving to 4
• API Changes since 6.x. No more Netty API Leaking through Finagle’s
• Mismatch between scala.concurrent.Future and com.twitter.util.Future
• Slow to update
• Documentation not exhaustive. Thanks for gitter.im and the Mailing List
• Can be painful to plug to other Metrics and Monitoring systems. Hopefully
it’s changing
finagle-mux provides a session layer RPC multiplexer. Mux allows session state to be maintained regardless of protocol encoding, meaning that any higher-level protocol (e.g. Thrift, HTTP) can be implemented on top of it. Clients and servers can thus be made more intelligent outside of the traditional request-response path. For example, you get failure accrual out-of-band of requests, as opposed to having the failure bookkeeping baked into your request-processing stack.