jaybe78

jaybe78

Hello,

I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).

The difficulty I’m facing is detecting gaps.

A user can be offline, lose connection, or messages can be dropped.
When user comes back from being offline, you need to return the latest data, and it needs to be in synced with the history stored in his phone.
when scrolling, it should also picks up gaps between latest messages and existing history.

All of that I think requires that each message when created has a global sequence per conversation.
I think that’s what “what’s app” does actually.

So my initial goal was to be able to get generate a global sequence per conversation which would be the source of truth, so that I can easily check arrived messages in my front end and if necessary query missing data from dynamob or the cache.

  1. I first tried to use dynamodb to get the message sequence with UPDATE_ITEM.
    But that would require one update(for the sequence) and one put(for the message).
    So one could your work and not the other… it’s not ideal

  2. Then the other option is to use a transaction, but the transaction cannot return the sequence after creation.
    It’s also more expensive and less scalable.

  3. Another one probably naive is to use ETS to increment a local sequence.
    All process sending messages would go through that to make sure the sequence is atomic across the node.
    When node goes down ets counter is lost and you’d get the latest sequence with a consistent read from dynamo, but you could have race condition.

  4. Increment sequence with ets and then PUT item with message and index. When the node goes down, the first time consistent read to get the latest sequence

Any idea how tackle this ?

Cheers

Showing Posts 1 to 6

allenwyma

allenwyma

What I did was when I reconnect, I’ll send the last received message ID and server will send back any missing messages so it can be caught up.

I did this over web socket on the client device. On the client I have a storage of some kind.

jaybe78

jaybe78 OP

Hello

I don’t think you understood my question.
I’m asking how to generate and maintain a reliable per-conversation ordering/sequence so I can detect gaps and reconcile chat history

allenwyma

allenwyma

No, I read it quite clearly.

As I said, upon reconnect: i send the last message ID per room, and ask for any messages following that, and the code will query any messages that came after that and send them back to the user. Just order by inserted_at and you can get that.

Is there a reason that the above won’t work?

allenwyma

allenwyma

Ah, i saw you mentioned dynamodb: that i haven’t worked a lot with:

but if you want to copy whatsapp: they are using jabberd: you’re welcome to copy that, of course. I believe they also keep an in-memory of each message and when you reconnect, they check that queue and send out the messages.

There’s quite a few ways to accomplish this.

jaybe78

jaybe78 OP

As I said, upon reconnect: i send the last message ID per room, and ask for any messages

Yes I suppose you do, but that does not say what is your messageID and how do you maintain order and consistency ?
That’s the whole point of my question. :slight_smile:

Is that a date ? a monotonous sequence ?

  • if it’s a date, how do you maintain consistency ? date would not allow you to detect gaps between 2 messages. Yes they would be in the right order, but that’s the only thing you can get from it.

  • if it’s a sequence, how do you maintain order of that sequence across your nodes ?
    Hence the suggestions I offered above.

Getting the “last message id”, would get you the latest messages received, but you could still have “holes” in there, and misalignments with the messages you have in your history.

No I don’t plan on redeveloping whats app lol, as you said, it would take some time, and to be honest, I’m not sure I have the knowledge and expertise to achieve such a thing on my own :slight_smile:

Though I guess there’s probably ways to develop an online chat that respect consistency across disconnect and netsplit :). It will not be as scalable as what’s app but it would respect those criterias.

Anyway cheers :slight_smile:

LostKobrakai

LostKobrakai

I’d consider if you can split up the parts you want to solve here. One is stable ordering. For that you can look at lamport clocks or vector clocks. The other is guaranteed delivery of messages, which is usually solved with acks and retries. You could do that on the individual message level or on chunks of message, whatever scale makes sense. And if you’re worried about detecting bugs (as in messages lost after acknowledgement) you could in intervals create e.g. checksums on sets of messages and compare them with the server.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews