Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

INTERFACE by apidays_Vulcain: beat GraphQL with HTTP/2+ by Kevin Dunglas


Consultez-les par la suite

1 sur 35 Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Similaire à INTERFACE by apidays_Vulcain: beat GraphQL with HTTP/2+ by Kevin Dunglas (20)


Plus par apidays (20)

Plus récents (20)


INTERFACE by apidays_Vulcain: beat GraphQL with HTTP/2+ by Kevin Dunglas

  1. 1. HTTP/2 Server Push
 and the rise of client-driven REST APIs
  2. 2. @dunglas - vulcain.rocks Kévin Dunglas ❏ Founder of Les-Tilleuls.coop ❏ Creator of Vulcain.rocks, Mercure.rocks, API Platform… ❏ Symfony Core Team Member @dunglas .social
  3. 3. @dunglas - vulcain.rocks REST Performance
  4. 4. @dunglas - vulcain.rocks REST Performance ❏ REST is designed to solve performance and scalability problems at internet-scale ❏ REST relies on a powerful caching model: clients and intermediates can cache ❏ HTTP implements this model © Google
  5. 5. @dunglas - vulcain.rocks The Under-Fetching and the N+1 Problems Not fetching enough data initially forces to issue subsequent requests, so creates waterfalls and increase latency.
  6. 6. @dunglas - vulcain.rocks The Over-Fetching Problem Generating and fetching too much data (data not used by clients) wastes bandwidth and computation power.
  7. 7. GraphQL: an Alternative to REST  « Fixing »  its Perf Issues (among other things…)
  8. 8. @dunglas - vulcain.rocks HTTP/2+
  9. 9. @dunglas - vulcain.rocks HTTP/2: Making the Web Faster ❏ Binary protocol, multiplexing, prioritization ❏ Server Push of resources ❏ Headers compression ❏ HTTP/3: good bye TCP (perf, again)
  10. 10. @dunglas - vulcain.rocks HTTP/2: Multiplexing © Narayan Prusty
  11. 11. @dunglas - vulcain.rocks HTTP/2: Server Push
  12. 12. @dunglas - vulcain.rocks HTTP/2 global support:
 95% of all internet users
  13. 13. @dunglas - vulcain.rocks CloudWays Benchmark (Not Using Server Push)
  14. 14. @dunglas - vulcain.rocks Fast and idiomatic client-driven REST APIs Introducing Vulcain
  15. 15. @dunglas - vulcain.rocks Pushing Relations
  16. 16. @dunglas - vulcain.rocks Consuming Pushes in JavaScript const outboxResp = await fetch("/outbox", { headers: { Preload: "/orderedItems/*" } }); const outbox = await outboxResp.json(); for (const url of outbox.orderedItems]) {     // Returns immediately, the resource has been pushed and is already in the push cache     const activityResp = await fetch(url);     const activity = await activityResp.json();     // Do something with the JSON document }
  17. 17. Without Vulcain With Vulcain
  18. 18. @dunglas - vulcain.rocks Benefits ❏ Fixes the under-fetching and N+1 problems ❏ Resources are downloaded in parallel (multiplexing) ❏ Granular HTTP cache (download only resources not already in cache) ❏ Respects REST principles ❏ Leverages all features of the HTTP protocol ❏ cache, authorization, content negotiation, extensibility…
  19. 19. @dunglas - vulcain.rocks Filtering Resources
  20. 20. @dunglas - vulcain.rocks Other Capabilities ❏ Selector negotiation: extended JSON Pointer, XPath, CSS selectors, JMESPath… ❏ Support using Link preload headers and the103 Early Hints status code instead of Server Push to preload cross-domain resources ❏ Use query parameters instead of HTTP headers ❏ Support non-hypermedia APIs through OpenAPI
  21. 21. @dunglas - vulcain.rocks The Vulcain Gateway Server
  22. 22. @dunglas - vulcain.rocks The Vulcain Gateway Server ❏ Instantly turns any existing hypermedia or non- hypermedia API into a Vulcain-enabled API ❏ Gateway server (plug’n’play network intermediate) ❏ Free software (open source) ❏ Fast, written in Go ❏ Easy to install (static binary, Docker image) ❏ Best performance: implement the protocol directly at the app server layer
  23. 23. @dunglas - vulcain.rocks Starting the Gateway Server
  24. 24. @dunglas - vulcain.rocks Mapping a Non- Hypermedia API
  25. 25. @dunglas - vulcain.rocks Mapping a Non-Hypermedia API # openapi.yaml openapi: 3.0.0 # ... paths:   '/books/{id}':     get:       # ...       responses:         default:           links:             author:               operationId: getAuthor               parameters:                 id: '$response.body#/author'   '/authors/{id}':     get:       operationId: getAuthor       responses:         default:       # ... // /books/1984 {     "title": "1984",     "author": 1 // Not an URI } // /authors/1 {     "givenName": "George",     "familyName": "Orwell" }
  26. 26. @dunglas - vulcain.rocks So… What About GraphQL?
  27. 27. @dunglas - vulcain.rocks Vulcain vs GraphQL: Performance ❏ Unlike GraphQL, Vulcain sends each pushed resource in a separate HTTP/2 stream (multiplexing): related resources are sent in parallel ❏ Embedding resources is a forced push: the client receive the full JSON documents, even if it already has some parts of it ❏ With Vulcain, clients can cancel the push of resources they already have, saving bandwidth and improving performance
  28. 28. @dunglas - vulcain.rocks But GraphQL is More Than That! ❏ Query Language ❏ Type System ❏ Introspection ❏ Subscriptions ❏ Great tooling
  29. 29. @dunglas - vulcain.rocks Type System and Introspection REST has that too… and a bit more! ❏ OpenAPI: type system and introspection ❏ JSON-LD: internet-scale type system,
 built on top of RDF, W3C standard ❏ Hydra: hypermedia introspection system,
 built on top of JSON-LD, W3C working group
  30. 30. @dunglas - vulcain.rocks Subscriptions
  31. 31. @dunglas - vulcain.rocks Tooling ❏ GraphQL provides great client-side tooling and an unified Developer Experience, REST is still behind ❏ But because GraphQL uses HTTP as a black box: ❏ HTTP Cache servers (Varnish, Nginx…) ❏ standard WAF (ModSecurity…) ❏ HTTP logs analyzer (GoAccess, AWStats…) ❏ API Gateways (Kong, Gravitee…) are almost useless
  32. 32. @dunglas - vulcain.rocks Tooling REST also has modern, easy to use client-side and server-side tooling: ❏ API Platform (PHP & JS): create JSON-LD APIs and smart React & Vue PWA, admin UIs, etc… in minutes! ❏ Graphiti (Ruby On Rails): create REST APIs in minutes ❏ Zeit’s SWR (React): Hook for HTTP APIs leveraging concurrent rendering (Vulcain’s perfect companion) ❏ Our upcoming JS lib! Stay tuned 🤯 Vulcain works out of the box with all these tools!
  33. 33. @dunglas - vulcain.rocks Summary Vulcain is: ❏ Fast (faster than GraphQL and JSON:API includes) ❏ Designed for the open web and interoperability at Internet-scale ❏ Easy to deploy ❏ Compatible with all existing tools leveraging HTTP ❏ Swagger/OpenAPI, log analyzers, Varnish, WAF, RDF… ❏ Can be supported in minutes by any web API ❏ including non-hypermedia APIs ❏ You can even use GraphQL to query a Vulcain API (apollo-rest-link)! Give it a try!
  34. 34. Thank you! vulcain.rocks - @dunglas - les-tilleuls.coop