Serverless Real-time Notifications for Web Apps in AWS
Written by Limor Leah Wainstein   
Monday, 23 July 2018

Using Serverless solutions for real-time communication for web apps solves many challenges. Implementing scalability, reliability and fault tolerance while dealing with WebSocket connections are few of them. When implementing real-time web applications, there are two services provided by AWS - AWS AppSync and AWS IoT. Each of these services has applicability for different use cases based on the features and pricing model they offer.


Real-Time Communication on the Web

When building modern real-time web applications, the technology enabler is WebSockets. Let's look at several advantages of using WebSockets for real-time communication.

  • Two-way communication: This allows the web browser to send messages to the server as well as for the server to send messages to the client. This is useful when sending notifications to the web browsers efficiently where it doesn't need to poll the backend for data.

  • Less overhead per message: WebSocket uses TCP without using HTTP(S). This saves the space for individual messages because the connection is already established and a given WebSocket data frame is very efficiently organized. Since WebSocket does not necessarily contain headers and cookies, it is a lot more efficient compared to HTTP(S) requests.

  • Stateful connections: Allows connection reuse and allows to keep the state inside an application for a given connection.


Although WebSockets provide many advantages, there are several challenges in using WebSockets. Some of the challenges include browser compatibility, which is mostly fine as of now; and the requirement for specialized tools and software for web servers that support WebSockets.

Message Processing and Persistence

It is also important to access the data sent via WebSockets and persist them. One option is to use a Serverless Solution to access the messages sent via WebSockets, using AWS Lambda by processing the messages received to AWS IoT or using Lambda resolvers for AppSync. You can store them either in AWS DynamoDB, S3 or in RDS based on the access patterns and query needs. It is also possible to use a streaming solution like AWS Kinesis if you receive a large number of messages and need to process them near real-time more efficiently. If you are using an EC2 instance, you can temporarily store the data received through WebSockets in an AWS EBS volumes and push them to permanent storage like S3 or DynamoDB (see this article for more details).

AWS AppSync vs AWS IOT WebSockets

Although both services support WebSockets, AWS AppSync is the newest introduction solving most of the problems we encounter in building real-time web applications. The main advantage is that it provides the necessary support to initiate the WebSocket connections and flexible Access Control models covering both B2C and B2B scenarios:

  • OPENID_CONNECT Authorization

  • AWS_IAM Authorization

  • API_KEY Authorization 


(click in image to enlarge)

AWS AppSync manages everything making sure that data updated in real time.


As the name suggests, AWS IoT is provide to connect mainly IOT devices as illustrated here:


(click in image to enlarge)

However, the WebSocket feature in AWS IOT can be used to implement real-time communication between Web Applications using WebSockets.

When using AWS IOT WebSockets, it uses MQTT messages over WebSockets. You can either use AWS IOT SDK for JavaScript or third-party JavaScript libraries to set up the WebSocket connections from the Web Browser.

However, it is important to note that, you will require temporary AWS Access Credentials either using Cognito Federated Identities using AWS STS in a backend for your Web Browser to communicate with AWS IOT.

When to Use What?

For web applications as well as application backend where the Real-Time communication happens after authentication, AppSync is preferred. AppSync not only allows query and push messages interface but also supports various delivery policies and validation criteria. One of the main advantages of AppSync is the support for GraphQL which can be fully integrated with Event Sourcing React/Angular Frontend Applications where AppSync can deliver the messages to persistence storages like AWS DynamoDB.

In terms of costs, AWS IoT WebSockets is much cheaper compared to AppSync. For basic real-time communication requirements like implementing a notification system, a simple public chat application or connecting IoT devices, you can use AWS IoT WebSockets.


Overall, AWS AppSync and AWS IOT both provide facilities to support real-time communication. As Serverless services, these services don't consume many resources at once and the service management overhead is already less. However, selecting the right service for the right job can be challenging. In general, for most of the use cases, it's more likely to go with AppSync unless you have a specific need such as IOT message publishing to a web dashboard or allowing public IoT Topics with large-scale public WebSockets support. 



More Information


AWS AppSync

Related Articles

Amazon's AWS IoT - Another IoT Backend

Choosing Tools for Efficient Deployment on AWS

Exploring Storage Options on AWS

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.




BusyBeaver(5) Is 47,176,870

The thing about the BusyBeaver function is that it is very easy to understand, but very difficult to compute. We now know its value up to 5, which isn't much progress for more than 50 years work.

Amazon Releases Free Courses On AI

A range of free self-paced courses on GenAI, have been released on AWS SkillBuilder, Amazon's online learning center where you can learn from AWS experts to build cloud skills online.

More News


kotlin book



or email your comment to:

Last Updated ( Monday, 23 July 2018 )