Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppSync/Graphql Multiple subscriptions or one subscriptions for multiple ids?

Problem : We are trying to make a chat application using AWS product AppSync and we want to achive the best performance but we're facing problem with real time subscriptions in AppSync and Graphql where a single user will need to handle hundereds of subscription in some cases which we think is not the best solution, what do you suggest ?

Problem Example:

Mutation{
    addMessage(conversation_id=Int!, content:String!) : Message
}
Subscription{
   subscribeForNewMessages(convesration_id: Int!):Message
        @aws_subscribe(mutations: ["addMessage"])
}

the problem with this design is that the user need to invoke this subscription and keep listening for every single conversation, which we expect to be overwheelming the client in case if the conversations quantity is huge.

Questions :

Q1 : What we are striving to achieve is one subscription for multiple (conversation_id)s, how this will be possible? These folks (https://github.com/apollographql/apollo-client/issues/2633) are talking about something similar, we tested it and it doesn't work, is it a valid solution?

Q2: Regarding Amplify; Will amplify perform well when listening for hundereds of subscription simulanuosly? does it make some sort of merging subscription and websockets or it will deal them separately?

Q3: what are your comments about these designs? where there will be a service that will braodcast(invoke mutations with clients ids) the messages for chat participants , and the client will subscribe only for a single channel . like the following: src2 : AWS AppSync for chatting application src2 : Subscribe to a List of Group / Private Chats in AWS AppSync

like image 637
Ahmad AlMashni Avatar asked Mar 18 '19 15:03

Ahmad AlMashni


People also ask

How do subscriptions work in GraphQL?

What are GraphQL subscriptions? Subscriptions are a GraphQL feature that allows a server to send data to its clients when a specific event happens. Subscriptions are usually implemented with WebSockets. In that setup, the server maintains a steady connection to its subscribed client.

What are AppSync subscriptions?

AppSync subscriptions allow you to push events to clients in real-time when a change happened. This is great for applications that show data that can change without user interaction, which is the case for almost all applications.

What is the difference between a GraphQL query and subscription?

Like queries, subscriptions enable you to fetch data. Unlike queries, subscriptions are long-lasting operations that can change their result over time. They can maintain an active connection to your GraphQL server (most commonly via WebSocket), enabling the server to push updates to the subscription's result.

Is AppSync scalable?

AWS AppSync is a serverless solution that allows you to build scalable real-time applications and take advantage of the optimized GraphQL layer at the same time.


1 Answers

Q1/Q2

You'll have to make multiple subscriptions and the aws ios/android/amplify sdks can handle subscription handshake protocols for real-time updates to data.

Take a look here

Q3

I recommend allowing clients to subscribe to specific channels (even if that means multiple subscriptions) so that the filtering logic can be done in the service rather than client side, reducing client side code which also means you don't have to worry about maintenance or scalability.

like image 162
Lisa M Shon Avatar answered Sep 28 '22 00:09

Lisa M Shon