we are building chat application similar to messenger. There is required behavior:
- User log in
- User should see last N messages, and he should be able to load older messages
- New messages should be appended as well
My solution:
- I would like to use websockets for this purpose with combination of REST. My idea was that client application decide by message id which messages need. So REST will be used for initial fetching of messages and fetching older messages.
- New messages will received by websockets
Possible issue which I should handle:
- Application starts subscribing websocket channel for new messages and send request for old messages without initial message id
- There is chance that after calling GET request new message come, and will be stored in DB
- Client application started subscribing websocket channel so message will received by websockets.
- GET request didn't know about this message and fetch last N messages where this new messages will occured and client application will have duplicate record and have to filtered this messages
Can you give me advice if there is some elegant way how to handle this case? Thank you.