8

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?

lcpnine
  • 477
  • 1
  • 7
  • 16

3 Answers3

11

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.

eDriven_Levar
  • 361
  • 3
  • 10
  • 2
    `It can triggered when a mutation takes place in your GraphQL server.` actually you can trigger it whenever you want to by sending a message to the pubsub server. – rbrc Oct 13 '22 at 14:20
8

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/

Tuan LE CONG
  • 367
  • 1
  • 8
1

For me, the comparison is really on Apollo gql subscriptions vs socket.io. The benefit of the former is it is a boxed solution that tells you how to do everything, and the benefit of the latter is that you get to implement how to do everything.

I've used both at scale; under the hood they're basically the same technology and there aren't any performance differences. If you're using a gql server, then stick with that.

rbrc
  • 872
  • 1
  • 6
  • 13