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.

D3247e8f4b25f6041ab71da426f1c86e?s=128

Ivayr Farah Netto

March 18, 2017
Tweet

Transcript

  1. Rescuing legacy codebases with GraphQL and Rails @nettofarah

  2. Netto Farah @nettofarah !"

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

    of salt
  4. None
  5. Context • Website, iOS app, Android app • Seasoned Rails

    3 codebase
  6. Technical Challenge • Build an entirely new website and mobile

    apps • Iterate fast (9 months deadline)
  7. We knew we needed to make some changes

  8. Majestic Monoliths vs Micro-services

  9. Not a binary decision

  10. A hybrid approach: Rich API + specific clients

  11. Challenges with Traditional APIs

  12. Multiple use cases

  13. with different access patterns

  14. Documentation and Conventions

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

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

  17. GraphQL a language specification for 
 defining and querying APIs

  18. Describe your data with TYPES

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

  20. Load just what you need

  21. query { rubygems {
 name downloads } }

  22. You can even load multiple entities at once

  23. query { rubygems {
 name, downloads } current_user { login,

    email } }
  24. Get predictable results

  25. { "data": { "rubygem": { "name": "rails", "downloads": 89321853 },

    “current_user": { "login": "nettofarah", "email": “nettofarah@gmail.com" } } }
  26. GraphQL focuses on the clients

  27. GraphQL + Ruby = ❤

  28. Demo time!

  29. RubyGems API Rubygem Version Dependency has_many has_many

  30. RubyGems API - use cases • list all available rubygems

    • search one specific rubygem by name
  31. Let’s see some code! http://bit.ly/gql-demo

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

    model
  33. GraphQL API as an integration layer for multiple (not so

    micro) services and front-ends
  34. GraphQL API ☁ A P I 
 G
 A
 T

    E
 W
 A Y Service A Service B Service C
  35. GraphQL API ⛈ A P I 
 G
 A
 T

    E
 W
 A Y Service A Service B Service C
  36. GraphQL in production

  37. What happened to semantic status codes?

  38. N+1 queries

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

  40. Monitoring and Errors

  41. None
  42. None
  43. None
  44. http://bit.ly/gql-rb-nr

  45. Where to go next? • graphql.org • graphql.slack.com (#ruby -

    I hang out there) • https://github.com/rmosolgo/graphql-ruby
  46. @nettofarah nettofarah@gmail.com