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

Fighting Legacy Codebases with GraphQL and Rails

Fighting Legacy Codebases with GraphQL and Rails

GraphQL is one of the hottest technologies of the past year or two. Still, very little is talked about GraphQL outside of the realm of front-end applications.

We used a different approach at IFTTT and applied GraphQL as an integration layer for different backends and client apps.

This talk goes beyond the basic configuration of a GraphQL endpoint with Rails. I’ll cover topics such ActiveRecord Query optimization, performance monitoring, batching and share some of the challenges we ran into while building a GraphQL API that serves over 10 thousand queries per minute.

Ivayr Farah Netto

March 18, 2017
Tweet

More Decks by Ivayr Farah Netto

Other Decks in Programming

Transcript

  1. Rescuing legacy codebases
    with GraphQL and Rails
    @nettofarah

    View Slide

  2. Netto Farah
    @nettofarah
    !"

    View Slide

  3. Conference speakers are
    professional enthusiasts
    Take this with a grain
    of salt

    View Slide

  4. View Slide

  5. Context
    • Website, iOS app, Android app
    • Seasoned Rails 3 codebase

    View Slide

  6. Technical Challenge
    • Build an entirely new website and mobile apps
    • Iterate fast (9 months deadline)

    View Slide

  7. We knew we needed
    to make some changes

    View Slide

  8. Majestic Monoliths
    vs
    Micro-services

    View Slide

  9. Not a binary
    decision

    View Slide

  10. A hybrid approach:
    Rich API + specific clients

    View Slide

  11. Challenges with
    Traditional APIs

    View Slide

  12. Multiple use cases

    View Slide

  13. with different
    access patterns

    View Slide

  14. Documentation
    and Conventions

    View Slide

  15. [%,",&..'] => ✅
    )

    View Slide

  16. )
    [!] =>
    ask me later…

    View Slide

  17. GraphQL
    a language specification for 

    defining and querying APIs

    View Slide

  18. Describe your data
    with TYPES

    View Slide

  19. type Rubygem {
    name: String
    downloads: Int
    versions: [Version]
    }

    View Slide

  20. Load just what
    you need

    View Slide

  21. query {
    rubygems {

    name
    downloads
    }
    }

    View Slide

  22. You can even load
    multiple entities at once

    View Slide

  23. query {
    rubygems {

    name, downloads
    }
    current_user {
    login, email
    }
    }

    View Slide

  24. Get predictable
    results

    View Slide

  25. {
    "data": {
    "rubygem": {
    "name": "rails",
    "downloads": 89321853
    },
    “current_user": {
    "login": "nettofarah",
    "email": “[email protected]"
    }
    }
    }

    View Slide

  26. GraphQL focuses on
    the clients

    View Slide

  27. GraphQL + Ruby = ❤

    View Slide

  28. Demo time!

    View Slide

  29. RubyGems API
    Rubygem Version
    Dependency
    has_many
    has_many

    View Slide

  30. RubyGems API - use cases
    • list all available rubygems
    • search one specific rubygem by name

    View Slide

  31. Let’s see some code!
    http://bit.ly/gql-demo

    View Slide

  32. We built a GraphQL API
    on top of our data model

    View Slide

  33. GraphQL API
    as an integration layer
    for multiple (not so micro) services
    and front-ends

    View Slide

  34. GraphQL
    API



    A
    P
    I

    G

    A

    T
    E

    W

    A
    Y
    Service A
    Service B
    Service C

    View Slide

  35. GraphQL
    API



    A
    P
    I

    G

    A

    T
    E

    W

    A
    Y
    Service A
    Service B
    Service C



    View Slide

  36. GraphQL in
    production

    View Slide

  37. What happened
    to semantic status codes?

    View Slide

  38. N+1 queries

    View Slide

  39. github.com/nettofarah/graphql-query-resolver

    View Slide

  40. Monitoring and
    Errors

    View Slide

  41. View Slide

  42. View Slide

  43. View Slide

  44. http://bit.ly/gql-rb-nr

    View Slide

  45. Where to go next?
    • graphql.org
    • graphql.slack.com (#ruby - I hang out there)
    • https://github.com/rmosolgo/graphql-ruby

    View Slide

  46. @nettofarah
    [email protected]

    View Slide