skip to Main Content

So I have a REST api. I want to keep it stateless, but at the sametime I need to make a real time chat.

The only way I can imagine a real time chat, is with websockets. The problem accurs that websockets, to my knowledge, seems pretty statefull.

Is there another way to create a real time chat?

My stack is Spring boot (java)
React frontend
Mongodb for database.

Plan for hosting would be AWS

And normally I would just ignore the 100% stateless or statefull, but this is for a school project, and I would look good in my report, to say I am 100% stateless.

2

Answers


  1. I know two ways of implementation this. Easiest – websockets. Hardest – backend is calling frontend.

    More about second solution. In normal world, we are calling backend using frontend, here will be visa versa. When backend will receive a message (from another user), it will tell frontend that message was received ant it should show it.

    Login or Signup to reply.
  2. the correct way achieving real time chats beside websockets would be to use firebase which is very common since usually the clients connected to your server will use android/iOS.

    obviously an app connected to firebase is maintaining a stateful connection to firebase.

    in general i dont think it is possible to provide push functionalities without state , as the server must reach the connected clients thus it must maintain those connections. if not using firebase, using websocket seems a reasonable approach.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search