Does Firebase always guarantee added events in order?












1















I am developing messenger IOS app based on Firebase Realtime Database.
I want that all messages to be ordered based on timestamp.



There is a scenario as like below.



There are 3 clients. A, B and C.



1)



All clients register 'figure-1' listener to receive messages from others.



<figure-1>

ref.queryOrdered(byChild: "timestamp").queryStarting(atValue: startTime).observe(.childAdded, with:
{
....
// do work for the messages, print, save to storage, etc.
....

// save startTime to storage for next open.
startTime = max(timeOfSnapshot, startTime)
saveToStorage(startTime)
}


2)



Client A write  message 1 to server with ServerValue.timestamp().
Client B write message 2 to server with ServerValue.timestamp().
Client C write message 3 to server with ServerValue.timestamp().


They sent messages extremely the same moment.



All clients have good speed wifi.



So, finally. Server data saved like 'figure-2'



<figure-2>

text : "Message 1", timestamp : 100000001
text : "Message 2", timestamp : 100000002
text : "Message 3", timestamp : 100000003




As my listener's code, i keep messages on storage and next listening timestamp for preventing downloading duplicated messages.



In this case.



Does Firebase always guarantee to trigger callback in order as like below?



Message 1
Message 2
Message 3


If it is not guaranteed, my strategy is absolutely wrong.



For example, some client received messages as like below.



Message 3  // the highest timestamp.

// app crash or out of storage

Message 1
Message 2


The client do not have chance to get message 1, 2 anymore.



I think if there are some nodes already, Firebase might trigger in order for those. Because, that is role of 'queryOrdered' functionality.



However, there are no node before register the listener and added new nodes additionally after then. What is will happen?



I suppose Firebase might send 3 packets to clients. (No matter how quickly the message arrives, Firebase has to send it out as soon as it arrives.)



Packet1 for message1
Packet2 for message2
Packet3 for message3

ClientA fail to receive for packet 1,2
ClientA success to receive for packet 3
Firebase re-send packet 1,2 again.
ClientA success to receive for packet 1,2


Eventually, all datas are consistent. But ordering is corrupted.



Does Firebase guarantee to occur events in order?



I have searched stack overflow and google and read official documents many times. However, i could not find the clear answer.



I have almost spent one week for this. Please give me piece of advice.










share|improve this question

























  • Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

    – Frank van Puffelen
    Nov 13 '18 at 14:13
















1















I am developing messenger IOS app based on Firebase Realtime Database.
I want that all messages to be ordered based on timestamp.



There is a scenario as like below.



There are 3 clients. A, B and C.



1)



All clients register 'figure-1' listener to receive messages from others.



<figure-1>

ref.queryOrdered(byChild: "timestamp").queryStarting(atValue: startTime).observe(.childAdded, with:
{
....
// do work for the messages, print, save to storage, etc.
....

// save startTime to storage for next open.
startTime = max(timeOfSnapshot, startTime)
saveToStorage(startTime)
}


2)



Client A write  message 1 to server with ServerValue.timestamp().
Client B write message 2 to server with ServerValue.timestamp().
Client C write message 3 to server with ServerValue.timestamp().


They sent messages extremely the same moment.



All clients have good speed wifi.



So, finally. Server data saved like 'figure-2'



<figure-2>

text : "Message 1", timestamp : 100000001
text : "Message 2", timestamp : 100000002
text : "Message 3", timestamp : 100000003




As my listener's code, i keep messages on storage and next listening timestamp for preventing downloading duplicated messages.



In this case.



Does Firebase always guarantee to trigger callback in order as like below?



Message 1
Message 2
Message 3


If it is not guaranteed, my strategy is absolutely wrong.



For example, some client received messages as like below.



Message 3  // the highest timestamp.

// app crash or out of storage

Message 1
Message 2


The client do not have chance to get message 1, 2 anymore.



I think if there are some nodes already, Firebase might trigger in order for those. Because, that is role of 'queryOrdered' functionality.



However, there are no node before register the listener and added new nodes additionally after then. What is will happen?



I suppose Firebase might send 3 packets to clients. (No matter how quickly the message arrives, Firebase has to send it out as soon as it arrives.)



Packet1 for message1
Packet2 for message2
Packet3 for message3

ClientA fail to receive for packet 1,2
ClientA success to receive for packet 3
Firebase re-send packet 1,2 again.
ClientA success to receive for packet 1,2


Eventually, all datas are consistent. But ordering is corrupted.



Does Firebase guarantee to occur events in order?



I have searched stack overflow and google and read official documents many times. However, i could not find the clear answer.



I have almost spent one week for this. Please give me piece of advice.










share|improve this question

























  • Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

    – Frank van Puffelen
    Nov 13 '18 at 14:13














1












1








1








I am developing messenger IOS app based on Firebase Realtime Database.
I want that all messages to be ordered based on timestamp.



There is a scenario as like below.



There are 3 clients. A, B and C.



1)



All clients register 'figure-1' listener to receive messages from others.



<figure-1>

ref.queryOrdered(byChild: "timestamp").queryStarting(atValue: startTime).observe(.childAdded, with:
{
....
// do work for the messages, print, save to storage, etc.
....

// save startTime to storage for next open.
startTime = max(timeOfSnapshot, startTime)
saveToStorage(startTime)
}


2)



Client A write  message 1 to server with ServerValue.timestamp().
Client B write message 2 to server with ServerValue.timestamp().
Client C write message 3 to server with ServerValue.timestamp().


They sent messages extremely the same moment.



All clients have good speed wifi.



So, finally. Server data saved like 'figure-2'



<figure-2>

text : "Message 1", timestamp : 100000001
text : "Message 2", timestamp : 100000002
text : "Message 3", timestamp : 100000003




As my listener's code, i keep messages on storage and next listening timestamp for preventing downloading duplicated messages.



In this case.



Does Firebase always guarantee to trigger callback in order as like below?



Message 1
Message 2
Message 3


If it is not guaranteed, my strategy is absolutely wrong.



For example, some client received messages as like below.



Message 3  // the highest timestamp.

// app crash or out of storage

Message 1
Message 2


The client do not have chance to get message 1, 2 anymore.



I think if there are some nodes already, Firebase might trigger in order for those. Because, that is role of 'queryOrdered' functionality.



However, there are no node before register the listener and added new nodes additionally after then. What is will happen?



I suppose Firebase might send 3 packets to clients. (No matter how quickly the message arrives, Firebase has to send it out as soon as it arrives.)



Packet1 for message1
Packet2 for message2
Packet3 for message3

ClientA fail to receive for packet 1,2
ClientA success to receive for packet 3
Firebase re-send packet 1,2 again.
ClientA success to receive for packet 1,2


Eventually, all datas are consistent. But ordering is corrupted.



Does Firebase guarantee to occur events in order?



I have searched stack overflow and google and read official documents many times. However, i could not find the clear answer.



I have almost spent one week for this. Please give me piece of advice.










share|improve this question
















I am developing messenger IOS app based on Firebase Realtime Database.
I want that all messages to be ordered based on timestamp.



There is a scenario as like below.



There are 3 clients. A, B and C.



1)



All clients register 'figure-1' listener to receive messages from others.



<figure-1>

ref.queryOrdered(byChild: "timestamp").queryStarting(atValue: startTime).observe(.childAdded, with:
{
....
// do work for the messages, print, save to storage, etc.
....

// save startTime to storage for next open.
startTime = max(timeOfSnapshot, startTime)
saveToStorage(startTime)
}


2)



Client A write  message 1 to server with ServerValue.timestamp().
Client B write message 2 to server with ServerValue.timestamp().
Client C write message 3 to server with ServerValue.timestamp().


They sent messages extremely the same moment.



All clients have good speed wifi.



So, finally. Server data saved like 'figure-2'



<figure-2>

text : "Message 1", timestamp : 100000001
text : "Message 2", timestamp : 100000002
text : "Message 3", timestamp : 100000003




As my listener's code, i keep messages on storage and next listening timestamp for preventing downloading duplicated messages.



In this case.



Does Firebase always guarantee to trigger callback in order as like below?



Message 1
Message 2
Message 3


If it is not guaranteed, my strategy is absolutely wrong.



For example, some client received messages as like below.



Message 3  // the highest timestamp.

// app crash or out of storage

Message 1
Message 2


The client do not have chance to get message 1, 2 anymore.



I think if there are some nodes already, Firebase might trigger in order for those. Because, that is role of 'queryOrdered' functionality.



However, there are no node before register the listener and added new nodes additionally after then. What is will happen?



I suppose Firebase might send 3 packets to clients. (No matter how quickly the message arrives, Firebase has to send it out as soon as it arrives.)



Packet1 for message1
Packet2 for message2
Packet3 for message3

ClientA fail to receive for packet 1,2
ClientA success to receive for packet 3
Firebase re-send packet 1,2 again.
ClientA success to receive for packet 1,2


Eventually, all datas are consistent. But ordering is corrupted.



Does Firebase guarantee to occur events in order?



I have searched stack overflow and google and read official documents many times. However, i could not find the clear answer.



I have almost spent one week for this. Please give me piece of advice.







ios firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:20









Frank van Puffelen

231k29379403




231k29379403










asked Nov 13 '18 at 12:23









Seung-Min JungSeung-Min Jung

236




236













  • Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

    – Frank van Puffelen
    Nov 13 '18 at 14:13



















  • Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

    – Frank van Puffelen
    Nov 13 '18 at 14:13

















Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

– Frank van Puffelen
Nov 13 '18 at 14:13





Also posted on groups.google.com/forum/#!topic/firebase-talk/U4sSXtR-pLU

– Frank van Puffelen
Nov 13 '18 at 14:13












1 Answer
1






active

oldest

votes


















2














The order in which the data for a query is returns is consistent, and determined by the server. So all clients are guaranteed to get the results in the same order.



For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order. The local client will see events for it's write operation right away though, before the data even reaches the database server.



In figure 2, it is actually quite simple: since each node has a unique timestamp, and they will be returned in the order of that timestamp. But even if they'd have the same timestamp, they'd be returned in the same order (timestamp first, then key) for each client.






share|improve this answer
























  • "For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

    – Seung-Min Jung
    Nov 13 '18 at 15:25













  • With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

    – Frank van Puffelen
    Nov 13 '18 at 17:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280940%2fdoes-firebase-always-guarantee-added-events-in-order%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The order in which the data for a query is returns is consistent, and determined by the server. So all clients are guaranteed to get the results in the same order.



For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order. The local client will see events for it's write operation right away though, before the data even reaches the database server.



In figure 2, it is actually quite simple: since each node has a unique timestamp, and they will be returned in the order of that timestamp. But even if they'd have the same timestamp, they'd be returned in the same order (timestamp first, then key) for each client.






share|improve this answer
























  • "For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

    – Seung-Min Jung
    Nov 13 '18 at 15:25













  • With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

    – Frank van Puffelen
    Nov 13 '18 at 17:33
















2














The order in which the data for a query is returns is consistent, and determined by the server. So all clients are guaranteed to get the results in the same order.



For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order. The local client will see events for it's write operation right away though, before the data even reaches the database server.



In figure 2, it is actually quite simple: since each node has a unique timestamp, and they will be returned in the order of that timestamp. But even if they'd have the same timestamp, they'd be returned in the same order (timestamp first, then key) for each client.






share|improve this answer
























  • "For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

    – Seung-Min Jung
    Nov 13 '18 at 15:25













  • With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

    – Frank van Puffelen
    Nov 13 '18 at 17:33














2












2








2







The order in which the data for a query is returns is consistent, and determined by the server. So all clients are guaranteed to get the results in the same order.



For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order. The local client will see events for it's write operation right away though, before the data even reaches the database server.



In figure 2, it is actually quite simple: since each node has a unique timestamp, and they will be returned in the order of that timestamp. But even if they'd have the same timestamp, they'd be returned in the same order (timestamp first, then key) for each client.






share|improve this answer













The order in which the data for a query is returns is consistent, and determined by the server. So all clients are guaranteed to get the results in the same order.



For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order. The local client will see events for it's write operation right away though, before the data even reaches the database server.



In figure 2, it is actually quite simple: since each node has a unique timestamp, and they will be returned in the order of that timestamp. But even if they'd have the same timestamp, they'd be returned in the same order (timestamp first, then key) for each client.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 14:19









Frank van PuffelenFrank van Puffelen

231k29379403




231k29379403













  • "For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

    – Seung-Min Jung
    Nov 13 '18 at 15:25













  • With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

    – Frank van Puffelen
    Nov 13 '18 at 17:33



















  • "For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

    – Seung-Min Jung
    Nov 13 '18 at 15:25













  • With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

    – Frank van Puffelen
    Nov 13 '18 at 17:33

















"For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

– Seung-Min Jung
Nov 13 '18 at 15:25







"For new data that is sent to the database after the listeners are attached, all remote clients will receive it in the same order" Did it mean that all clients will receive ordered datas(ordering : Message 1, 2, 3 )? Is it guarantee that they will not receive 'Message 2' until 'Message 1' arrived?

– Seung-Min Jung
Nov 13 '18 at 15:25















With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

– Frank van Puffelen
Nov 13 '18 at 17:33





With the code and the JSON you've shown, the messages will indeed arrive in the order Message 1 Message 2 Message 3.

– Frank van Puffelen
Nov 13 '18 at 17:33


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280940%2fdoes-firebase-always-guarantee-added-events-in-order%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues