# Maintaining WebSocket Connections with GraphQL Subscriptions in a Serverless Environment

DevFeed: [Maintaining WebSocket Connections with GraphQL Subscriptions in a Serverless Environment](<https://devfeed.tech/articles/staying-connected-19123.md>)

Original publisher: [Read original article](<https://medium.com/rbi-tech/staying-connected-48c00670cea8?source=rss----904782439303---4>)

Author: Shaila Kavrakova

Published: 2021-03-31T14:49:04Z

Content type: tutorial

Language: en

Sources: [RBI Tech](<https://devfeed.tech/sources/rbi-tech.md>)

Topics: [WebSocket](<https://devfeed.tech/topics/websocket.md>), [Serverless](<https://devfeed.tech/topics/serverless.md>), [serverless architecture](<https://devfeed.tech/topics/serverless-architecture.md>), [AWS Lambda](<https://devfeed.tech/topics/aws-lambda.md>), [Amazon API Gateway](<https://devfeed.tech/topics/amazon-api-gateway.md>), [GraphQL](<https://devfeed.tech/topics/graphql.md>)

Tags: [amazon-api-gateway](<https://devfeed.tech/tags/amazon-api-gateway.md>), [apollo](<https://devfeed.tech/tags/apollo.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-lambda](<https://devfeed.tech/tags/aws-lambda.md>), [graphql](<https://devfeed.tech/tags/graphql.md>), [serverless](<https://devfeed.tech/tags/serverless.md>), [serverless-architecture](<https://devfeed.tech/tags/serverless-architecture.md>), [web-applications](<https://devfeed.tech/tags/web-applications.md>), [websocket](<https://devfeed.tech/tags/websocket.md>)

## AI overview

This article explains how WebSockets provide persistent, bidirectional communication for real-time web applications and examines the challenge of using them with event-driven serverless architecture. It introduces AWS Lambda and Amazon API Gateway as relevant components.

## Source excerpt

Maintaining a sustained connection with WebSockets and GraphQL Subscriptions in a serverless environment Photo by https://unsplash.com/@plhnk As modern technology and web applications advance, the expectation of immediate feedback and constant communication is apparent. We're accustomed to this phenomenon of instant gratification where we are fulfilled with very little or hardly any wait time at all. Just think about how we're able to receive certain packages with same day delivery. The world is at our finger tips. This continuous cause and effect cycle needs to be seamless, otherwise you run the risk of the end user becoming impatient or frustrated. WebSockets One way to achieve real time updates is through a persistent connection. This is where WebSockets come into play. A WebSocket is a transport protocol which provides a bi-directional communication channel between client and server via a sustained connection. Typical HTTP/S requests are uni-directional meaning only allowing for requests to be sent from client to server. WebSockets render polling (aka constant request/response cycles) obsolete. Once a connection is established, connection channels persist and are re-used to exchange messages back-and-forth. Some popular use cases for WebSockets are real time applications such as chat apps and multiplayer games. The server is able to push new updates without the need for frequent requests from the client. Instant gratification! Serverless Serverless architecture enables us to build and run our applications without the infrastructure overhead. When it comes to serverless, it's helpful to keep in mind that it is strictly event based. Events trigger other events. In the case of AWS Lambda, it will run our code on an as-needed basis in response to a given event. Due to this, it is not a long running process and is very transactional in nature. This brings me to the question at hand, what if we wanted to take advantage of WebSockets but with all the advantages of serv