$30 off During Our Annual Pro Sale. View Details »

REST or GraphQL? A Performance Comparative Study

Gustavo Pinto
September 24, 2019
170

REST or GraphQL? A Performance Comparative Study

Gustavo Pinto

September 24, 2019
Tweet

Transcript

  1. REST or GraphQL?
    A Performance Comparative Study
    Marcos Nazário
    @gustavopinto
    Gustavo Pinto
    Matheus Seabra

    View Slide

  2. ?
    @gustavopinto

    View Slide

  3. HTTP
    @gustavopinto
    REST

    View Slide

  4. @gustavopinto

    View Slide

  5. @gustavopinto

    View Slide

  6. @gustavopinto

    View Slide

  7. @gustavopinto
    GET https://hacker-news.firebaseio.com/v0/post/8863

    View Slide

  8. @gustavopinto
    GET https://hacker-news.firebaseio.com/v0/post/8863/points

    View Slide

  9. @gustavopinto
    https://hacker-news.firebaseio.com/v0/post/8863/author/
    GET https://hacker-news.firebaseio.com/v0/post/8863/author

    View Slide

  10. @gustavopinto
    https://hacker-news.firebaseio.com/v0/post/8863/when/
    GET https://hacker-news.firebaseio.com/v0/post/8863/when

    View Slide

  11. @gustavopinto
    https://hacker-news.firebaseio.com/v0/post/8863/flag
    POST https://hacker-news.firebaseio.com/v0/post/8863/flag

    View Slide

  12. @gustavopinto
    https://hacker-news.firebaseio.com/v0/post/8863/author/hide
    POST https://hacker-news.firebaseio.com/v0/post/8863/hide

    View Slide

  13. @gustavopinto
    GET https://hacker-news.firebaseio.com/v0/post/8863/comments

    View Slide

  14. @gustavopinto
    GET https://hacker-news.firebaseio.com/v0/post/8863

    View Slide

  15. @gustavopinto
    {
    "by": "pg",
    "descendants": 54,
    "id": 126809,
    "kids": [
    126822,
    126823,
    126917,
    126993,
    126824,
    126934,
    127072,
    127217,
    126889,
    126875,
    127535
    ],
    "score": 47,
    "time": 1204403652,
    "title": "Poll: What would
    happen if News.YC had explicit
    support for polls?",
    "type": "poll"
    "score" : 25,
    "text" : "or HN: the Next
    IterationI get the impression that with
    Arc being released a lot of people who never
    had time for HN before are suddenly dropping
    in more often. (PG: what are the numbers on
    this? I'm envisioning a spike.)Not to say
    that isn't great, but I'm wary of
    Diggification.80% of the stuff that makes
    the front page is still pretty awesome, but
    what's in place to keep the signal/noise
    ratio high? Does the HN model still work as
    the community scales? What's in store for (++
    HN)?",
    "time" : 1203647620,
    "title" : "Ask HN: The Arc Effect",
    "type" : “story"
    "text" : "Yes, ban them; I'm tired of seeing
    Valleywag stories on News.YC.",
    "time" : 1207886576,
    "type" : "pollopt"
    "parts": [
    126810,
    126811,
    126812
    ]
    }
    GET https://hacker-news.firebaseio.com/v0/post/8863

    View Slide

  16. @gustavopinto
    {
    "by": "pg",
    "descendants": 54,
    "id": 126809,
    "kids": [
    126822,
    126823,
    126917,
    126993,
    126824,
    126934,
    127072,
    127217,
    126889,
    126875,
    127535
    ],
    "score": 47,
    "time": 1204403652,
    "title": "Poll: What would
    happen if News.YC had explicit
    support for polls?",
    "type": "poll"
    "score" : 25,
    "text" : "or HN: the Next
    IterationI get the impression that with
    Arc being released a lot of people who never
    had time for HN before are suddenly dropping
    in more often. (PG: what are the numbers on
    this? I'm envisioning a spike.)Not to say
    that isn't great, but I'm wary of
    Diggification.80% of the stuff that makes
    the front page is still pretty awesome, but
    what's in place to keep the signal/noise
    ratio high? Does the HN model still work as
    the community scales? What's in store for (++
    HN)?",
    "time" : 1203647620,
    "title" : "Ask HN: The Arc Effect",
    "type" : “story"
    "text" : "Yes, ban them; I'm tired of seeing
    Valleywag stories on News.YC.",
    "time" : 1207886576,
    "type" : "pollopt"
    "parts": [
    126810,
    126811,
    126812
    ]
    }
    GET https://hacker-news.firebaseio.com/v0/post/8863

    View Slide

  17. @gustavopinto
    GET https://hacker-news.firebaseio.com/v0/post/8863
    GET https://hacker-news.firebaseio.com/v0/post/8864
    GET https://hacker-news.firebaseio.com/v0/post/8865
    GET https://hacker-news.firebaseio.com/v0/post/8866

    View Slide

  18. @gustavopinto

    View Slide

  19. @gustavopinto
    GraphQL
    Developed by Facebook
    Publicly released on 2015

    View Slide

  20. @gustavopinto
    GraphQL
    Developed by Facebook
    Publicly released on 2015
    GraphQL allows clients to define the
    structure of the data required, and
    exactly the same structure of the data
    is returned from the server, therefore
    preventing excessively large amounts
    of data from being returned


    View Slide

  21. @gustavopinto
    type Query {

    topStories(limit: Int): [Story]

    }

    View Slide

  22. {
    "data": {
    "hn": {
    "topStories": [
    {
    "title": "Monte Carlo methods Why it's a bad
    idea to go to the casino"
    },
    {
    "title": "Public Domain Movies"
    },
    {
    "title": "Agent 355"
    }
    ]
    }
    @gustavopinto
    type Query {

    topStories(limit: Int): [Story]

    }

    View Slide

  23. Research Questions
    RQ: Which architectural
    model is the most efficient
    in terms of performance?
    @gustavopinto

    View Slide

  24. APP1 APP2 APP3
    RocketBox TechTeams MyFeed
    @gustavopinto

    View Slide

  25. APP1 APP2 APP3
    RocketBox TechTeams MyFeed
    (Dropbox simplified) (Trello simplified) (Twitter simplified)
    @gustavopinto

    View Slide

  26. APP1 APP2 APP3
    Rest Rest Rest
    RocketBox TechTeams MyFeed
    (Dropbox simplified) (Trello simplified) (Twitter simplified)
    @gustavopinto

    View Slide

  27. APP1 APP2 APP3
    Rest GraphQL Rest GraphQL Rest GraphQL
    RocketBox TechTeams MyFeed
    (Dropbox simplified) (Trello simplified) (Twitter simplified)
    @gustavopinto

    View Slide

  28. APP1 APP2 APP3
    Rest GraphQL Rest GraphQL Rest GraphQL
    RocketBox TechTeams MyFeed
    (Dropbox simplified) (Trello simplified) (Twitter simplified)
    350 LoC 270 LoC 471 LoC 388 LoC 171 LoC 265 LoC
    @gustavopinto

    View Slide

  29. APP1 APP2 APP3
    Rest GraphQL Rest GraphQL Rest GraphQL
    RocketBox TechTeams MyFeed
    (Dropbox simplified) (Trello simplified) (Twitter simplified)
    350 LoC 270 LoC 471 LoC 388 LoC 171 LoC 265 LoC
    JavaScript
    @gustavopinto

    View Slide

  30. network overhead Rest
    GraphQL
    Client
    @gustavopinto

    View Slide

  31. GraphQL
    Client
    Rest
    @gustavopinto

    View Slide

  32. GraphQL
    Client
    Rest
    GraphQL
    Client
    @gustavopinto

    View Slide

  33. GraphQL
    Client
    Rest
    GraphQL
    1
    2
    3
    100 requests
    1000 requests
    3000 requests
    {
    15x
    Client
    1, 10, 100 users
    1, 500, 1000 users
    1, 1000, 3000 users
    Intel Core i7, 2.20GHz,
    8 cores, 16 GB memory,
    running Ubuntu Linux
    @gustavopinto

    View Slide

  34. Size of the document
    @gustavopinto

    View Slide

  35. Size of the document
    No reduction
    @gustavopinto

    View Slide

  36. Size of the document
    No reduction
    Reduction in
    100% of the
    cases
    @gustavopinto

    View Slide

  37. Size of the document
    No reduction
    Reduction in
    100% of the
    cases
    Reduction in
    50% of the
    cases
    @gustavopinto

    View Slide

  38. Size of the document
    No reduction
    Reduction in
    100% of the
    cases
    Reduction in
    50% of the
    cases
    @gustavopinto

    View Slide

  39. Time per request (ms)
    @gustavopinto

    View Slide

  40. Time per request (ms)
    @gustavopinto

    View Slide

  41. Time per request (ms)
    @gustavopinto

    View Slide

  42. Time per request (ms)
    @gustavopinto

    View Slide

  43. Time per request (ms)
    @gustavopinto

    View Slide

  44. View Slide