Build a Chat service using GoLang and WebAssembly (part 3)
Tags: webassembly, go, chat
Published: 2022-07-20 06:14:16

Gooood :)))) now we are in part 3 - we wanna talk about **Chat Service Architecture**

A chat service consists of two major parts:

- **Chat App** or client part, which is a desktop, web, or smartphone chat application.

- **Chat Server Engine** or server part, which is a pool of external servers responsible for the chat operation. This is the place where all the chat magic happens.

Both parts contain various components that communicate to each other and bring the chat into action.

![Chat Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/srxfylj9uq1h31hs8kih.png)
 
**Chat Server Engine** is a core of the chat architecture that handles message delivery and dispatch. I want to show you all components in chat service:

- **Chat REST API** handles the tasks that are not connected directly to message dispatch and delivery, such as user authentication, changing of user settings, friends invitation, downloading sticker packs, etc. The Chat App (the chat client part) communicates with the Chat REST API via the Chat REST API Client Library.

- **Chat WebSocket Server** is responsible for transmitting messages between users. The Chat App communicates with the Chat WebSocket Server via the Chat WebSocket Client Library. This connection is open two ways; that means users don’t have to make requests to the server if there are any messages for them, they just get them right away.

- **Chat Media Storage Server** is a pool of servers responsible for storing user media files. The files are uploaded to them via the Chat Media Storage Client Library.

**Chat App** is the other major part of the chat architecture, the one that users directly interact with. It's split into three separate root components:

- **Chat Client Engine** handles all of the communication with the Chat Server Engine via its internal components: Chat REST API Client Library, Chat WebSocket Client Library and Chat Media Storage Client Library. It also comprises the **Chat Push Message Handler** that deals with push notifications.

- **Chat UI** displays data to users via its widgets: **Chat Contact List UI, Chat Dialog UI, Chat Push Message Widget** — extension for mobile apps that allow for replying to messages without opening the app and **Chat Internal Notification Widget** — a widget that pops up at the top of the screen while the user is chatting in a dialog and notifies about the incoming message in another dialog.

- **Chat Device Storage** is an internal database (read: your device storage), which stores messages and files so that users can access them offline. Its internal component, **Chat Media Cache**, gets media files from the Chat Media Storage and stores them on the device so that the user can access them anytime without having to reach the Chat Media Storage every time.

So we need **WebSocket** protocol that makes it possible to open a two-way interactive communication session between the user's browser and a server. so you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

![Image Websocket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dincge3wb3jtzfeerrk.png)

In our project we create a **websocket server with nodejs** and a **websocket client with Golang** 

References:
1) [yellow.systems: Chat Service Architecture](https://yellow.systems/blog/guide-to-the-chat-architecture)
2) [developer.mozilla.org: WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
 
---

In part 4 we are going to write our websocket server with nodejs😉