Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL Subscriptions vs socket.io

I'm trying to make real-time application based on websocket and got two options. One is socket.io and the other is GraphQL Subscriptions. But it was hard to find comparison of those.

What can be standard to choose one of them and is there any performance difference?

like image 581
lcpnine Avatar asked Jan 25 '23 11:01

lcpnine


2 Answers

Here's my comparison as I had the same situation.

GraphQL Subscriptions - Give updates when the data changes. It can triggered when a mutation takes place in your GraphQL server. This is great as it keeps your logic tightly coupled. However, in the use case of a "Chat" application. This isn't the best.

Socket.IO - Provides a 2 Way Event notification services. Therefore, you can send event from the clients without waiting on a GraphQL mutation to be executed. For example: "User A is Typing..." Or a User enters or leaves the conversation.

like image 173
eDriven_Levar Avatar answered Jan 28 '23 04:01

eDriven_Levar


Socket.IO is a library that enables real-time, bidirectional and event-based communication between the browser and the server. socket.io

GraphQL Subscriptions on another hand is a concept that allows clients to listen to real-time messages from the server.

So basically, GraphQL Subscriptions is a specification that defines the policies & rules that allow GraphQL clients and servers to communicate in real-time. And to implement the feature, you can use real-time tools like Socket.io.

For more detail, you can take a look at: https://dgraph.io/docs/graphql/subscriptions/

like image 33
Tuan LE CONG Avatar answered Jan 28 '23 03:01

Tuan LE CONG