|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.
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:
(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.
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.
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.
or email your comment to: email@example.com
|Last Updated ( Monday, 23 July 2018 )|