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

Paris.js - Real-time apps with GraphQL, Node.js and MQTT

Paris.js - Real-time apps with GraphQL, Node.js and MQTT

Presentation slides for Paris.js in Paris, Jan 25th 2017.

Jacopo Daeli

January 25, 2017
Tweet

More Decks by Jacopo Daeli

Other Decks in Technology

Transcript

  1. What a real-time applications are? They are apps that must

    guarantee response within specified time constraints to specific events. These time constraints depend from the kind of application you are developing. Self-driving cars are one of the most amazing example of real-time applications. The have really strict time constraints… otherwise you will be dead.
  2. What a real-time applications are? Chat messaging applications should be

    real-time too. I believe in a good messaging application a message should go from UserA to UserB within 100 ms. Facebook built a really cool scalable mobile-first infrastructure for Messenger capable to send a message from one user to another in under 100 ms. FB Messenger is clearly a good example of real-time chat messaging application.
  3. Protocols for getting data down? Pull-based approach. The client first

    receive a lightweight message (maybe over web sockets) indicating new data is available, and then it sends the server a more complicated http request asking for the data. Push-based approach. The client first retrieves an initial snapshot of the data (generally with an http request) and then subscribes to delta updates, which are immediately pushed to the app (maybe through MQTT).
  4. What is GraphQL? GraphQL is a query language for your

    API, and a server- side runtime for executing queries by using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.
  5. Why GraphQL? Mainly because: • You may have different clients

    (e.g. web, iOS, Android) that render data differently • You may have to care about latency and bandwidth, especially in real-time applications • You may want to quickly decouple front-ends and back-ends GraphQL allows each client to query exactly what it needs, in the format it needs. It is the clean layer of abstraction between servers and clients that an ad-hoc REST approach will never be able to provide.
  6. GraphQL in practice GraphQL exposes three operations: Queries (to read

    data), Mutations (to write data), and Subscriptions (to receive data updates).
  7. What is MQTT? MQTT (MQ Telemetry Transport) is a pubsub-based

    lightweight messaging protocol to use on top of the TCP/ IP protocol.
  8. Why MQTT? MQTT is ideal for real-time applications (especially if

    mobile) because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers.
  9. The concept GraphQL MQTT Subscribe Subscribe Mutation API Run Mutation

    Mutation Response MQTT <resource>_<id>: Client<id>(query x)
  10. The concept GraphQL MQTT Subscribe Subscribe Mutation API Run Mutation

    Mutation Response Publish MQTT <resource>_<id>: Client<id>(query x)
  11. The concept GraphQL MQTT Subscribe Subscribe Mutation API Run Mutation

    Mutation Response Publish MQTT MQTT <resource>_<id>: Client<id>(query x)
  12. The concept GraphQL MQTT Subscribe Subscribe Run Subscriptions GraphQL Responses

    Mutation API Run Mutation Mutation Response Publish
  13. The concept GraphQL MQTT Subscribe Push update Subscribe Push update

    Run Subscriptions GraphQL Responses Mutation API Run Mutation Mutation Response Publish
  14. Why Node.js? Node is fun. Node has a well-maintained GraphQL

    package. It also has two fantastic modules call mqtt- connection and mqtt. All of them available on npm. It is easier to use these three libraries together to build a fully working Node.js application.