Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Netty at Twitter with Finagle

Netty at Twitter with Finagle

A minimal set of slides used to present an overview of Finagle, an RPC library built atop Netty

Evan Meagher

July 29, 2014
Tweet

More Decks by Evan Meagher

Other Decks in Programming

Transcript

  1. @TwitterAds | Confidential
    Evan Meagher (@evanm)
    7/28/14
    Netty at Twitter with Finagle

    View Slide

  2. @Twitter 2
    Agenda
    Why and what is Finagle?
    What does it do?
    What are we working on now?

    View Slide

  3. @Twitter 3
    What is Finagle?

    View Slide

  4. @Twitter 4
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  5. @Twitter 5
    Why did we build Finagle?

    View Slide

  6. @Twitter 6
    In the beginning…

    View Slide

  7. @Twitter 7
    Monolithic Rails app
    MySQL

    View Slide

  8. @Twitter 8
    Monolithic
    Rails app
    MySQL
    Monolithic
    Rails app
    MySQL
    Monolithic
    Rails app
    MySQL
    … Monolithic
    Rails app
    MySQL


    View Slide

  9. @Twitter 9

    View Slide

  10. @Twitter 10

    View Slide

  11. @Twitter 11
    What is Finagle?

    View Slide

  12. @Twitter 12
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  13. @Twitter 13
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  14. @Twitter 14
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  15. @Twitter 15
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  16. @Twitter 16
    An open source, protocol-agnostic,
    asynchronous RPC library for the JVM

    View Slide

  17. @Twitter 17
    What does Finagle do?

    View Slide

  18. @Twitter 18
    Standardizes the edges in a “boxes and
    arrows” network diagram

    View Slide

  19. @Twitter 19
    [1] http://monkey.org/~marius/funsrv.pdf

    View Slide

  20. @Twitter 20
    type Service[Req, Rep] = Req => Future[Rep]

    View Slide

  21. @Twitter 21
    type Service[Req, Rep] = Req => Future[Rep]
    Server
    Client
    Req
    Future[Rep]

    View Slide

  22. @Twitter 22
    A contrived example

    View Slide

  23. @Twitter 23
    val server = new Service[HttpReq, HttpRep] {
    def apply(req: HttpReq): Future[HttpRep] =
    Future.value(HttpRep(Status.OK, req.body))
    }
    !
    Http.serve(":80", server)

    View Slide

  24. @Twitter 24
    val client: Service[HttpReq, HttpRep] =
    Http.newService(“twitter.com:80")
    !
    val futureResponse: Future[HttpRep] =
    client(HttpReq(“/"))
    !
    futureResponse map { response =>
    println(response)
    }

    View Slide

  25. @Twitter 25
    Now let’s say you need to
    authenticate requests

    View Slide

  26. @Twitter 26
    type Service[Req, Rep] = Req => Future[Rep]
    !
    type Filter[Req, Rep] =
    (Req, Service[Req, Rep]) => Future[Rep]

    View Slide

  27. @Twitter 27
    type Service[Req, Rep] = Req => Future[Rep]
    !
    type Filter[Req, Rep] =
    (Req, Service[Req, Rep]) => Future[Rep]
    Filter Filter Server
    Client

    View Slide

  28. @Twitter 28
    def isAuthed(req: Req): Boolean
    val authFilter: Filter[HttpReq, HttpRes] = {
    (req, svc) =>
    if (isAuthed(req)) svc(req)
    else Future.exception(new AccessDenied)
    }
    !
    val authedServer: Service[HttpReq, HttpRes] =
    authFilter andThen server

    View Slide

  29. @Twitter 29
    val instrumentedServer = authFilter
    andThen traceRequest
    andThen recordStats
    andThen server

    View Slide

  30. @Twitter 30
    What are we working on now?

    View Slide

  31. @Twitter 31
    Service discovery
    See the “Names” page on the Finagle user guide:
    http://twitter.github.io/finagle/guide/Names.html
    !
    val client = Http.newService(
    “zk!myzkhost.mycompany.com:2181!/my/zk/path”
    )

    View Slide

  32. @Twitter 32
    Load balancing

    View Slide

  33. @Twitter 33
    Request multiplexing
    See the “Protocols” page on the Finagle user guide:
    http://twitter.github.io/finagle/guide/Protocols.html

    View Slide

  34. @Twitter 34
    Tail-latency optimization

    View Slide

  35. @TwitterAds | Confidential
    Thanks!
    github.com/twitter/finagle
    @finagle
    @evanm

    View Slide