DEV Community

Cover image for Converting a custom chat to use serverless AWS for it's backend (Part 1: The Setup)
Roy Ronalds
Roy Ronalds

Posted on

Converting a custom chat to use serverless AWS for it's backend (Part 1: The Setup)

The browser based game http://www.ninjawars.net has a chat that I developed a few years ago that is purely EC2 server based. The background websockets server of the chat is run directly off of a debian EC2 server. These days, I write stuff in serverless AWS and often use AppSync. So I thought it was high time to convert this chat from using a custom websockets backend to using the AWS appsync subscription approach for a different method of real-time updates.

Convert websockets chat to appsync

Current system

Right now, the way the chat works is:

  1. It initializes with the chats that are already in the system from the database
  2. When a user sends a new chat, it instantly sends that as some json to the websockets server
  3. the websockets server broadcasts the message to other browser clients, which append the chat to the chat area

Simple enough.

However, the websockets server is based on a php package http://socketo.me/ , and sometimes that mini-app goes down without warning, leaving the chat to fallback to an old-school chat-archive. Even monitoring and being certain that the chat websocket server is -up- isn't obvious.

How to build a chat today

Ok, so that's the previous approach with websockets, what will the version 2 be like?

Well, having used amplify + DynamoDB + Datastore, Datastore makes it simple to pull data and send up data in an offline-app compatible way, as well as having a subscription to new incoming data. So first attempt is going to be using DynamoDB, Amplify, and Datastore, generally ignoring auth for the purposes of this simple app, for now.

Diagram of the intended data flow
Above is a diagram of the intended data flow for a simple chat using Amplify Datastore.

I'm working on the architecture for this, more on the results and modifications to come in part 2!

Latest comments (0)