Offline Usage. Flutter Hamilton App Architecture. Write to Node and Expect Cloud Function to Update Database...












6















The following quote is taken from Google Developer Blog. https://developers.googleblog.com/2017/08/hamilton-app-takes-stage.html




For example, when someone enters the lottery, the app first writes
data to specific nodes in Realtime Database and the database's
security rules help to ensure that the data is valid. The write
triggers a Cloud Function, which runs business logic and stores its
result to a new node in the Realtime Database. The newly written
result data is then pushed automatically to the app.




I understand that instead of making a request and expecting a request, they followed the following pattern:




  1. Write to real-time database

  2. The write trigger an action

  3. The action triggers some logic and function

  4. The function writes data back to the database

  5. The listener on the app gets a notification about the data written on 4.

  6. App updates UI or takes whatever action.


Hamilton app followed this pattern when someone enters the competition for a ticket. My main concern with the pattern is that if the connection is offline, we won't get results and at the same time we won't get an error. The changes will be updated locally and firebase will update the next time there is a connection, which will make things messy, as the user is expecting a result.



I was wondering if there is an easy way or a pattern to follow, so we will get an error and display it.



The first solution that comes to my mind is to somehow add a time on the save operation. If the save is not done on the live database within x seconds then we display an error. At the same time, we will also need a timeout on the reply. So if we do not get a reply within x seconds we display something to the user.



I hope I am not confused as I did not understand the pattern well. I struggled with the title, so if anyone can improve it, please be my guest.










share|improve this question























  • Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

    – Swift
    Jun 3 '18 at 19:43











  • Unfortunately not. Can you please upvote so it get a bit more attention.

    – zirinisp
    Jun 5 '18 at 10:59
















6















The following quote is taken from Google Developer Blog. https://developers.googleblog.com/2017/08/hamilton-app-takes-stage.html




For example, when someone enters the lottery, the app first writes
data to specific nodes in Realtime Database and the database's
security rules help to ensure that the data is valid. The write
triggers a Cloud Function, which runs business logic and stores its
result to a new node in the Realtime Database. The newly written
result data is then pushed automatically to the app.




I understand that instead of making a request and expecting a request, they followed the following pattern:




  1. Write to real-time database

  2. The write trigger an action

  3. The action triggers some logic and function

  4. The function writes data back to the database

  5. The listener on the app gets a notification about the data written on 4.

  6. App updates UI or takes whatever action.


Hamilton app followed this pattern when someone enters the competition for a ticket. My main concern with the pattern is that if the connection is offline, we won't get results and at the same time we won't get an error. The changes will be updated locally and firebase will update the next time there is a connection, which will make things messy, as the user is expecting a result.



I was wondering if there is an easy way or a pattern to follow, so we will get an error and display it.



The first solution that comes to my mind is to somehow add a time on the save operation. If the save is not done on the live database within x seconds then we display an error. At the same time, we will also need a timeout on the reply. So if we do not get a reply within x seconds we display something to the user.



I hope I am not confused as I did not understand the pattern well. I struggled with the title, so if anyone can improve it, please be my guest.










share|improve this question























  • Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

    – Swift
    Jun 3 '18 at 19:43











  • Unfortunately not. Can you please upvote so it get a bit more attention.

    – zirinisp
    Jun 5 '18 at 10:59














6












6








6








The following quote is taken from Google Developer Blog. https://developers.googleblog.com/2017/08/hamilton-app-takes-stage.html




For example, when someone enters the lottery, the app first writes
data to specific nodes in Realtime Database and the database's
security rules help to ensure that the data is valid. The write
triggers a Cloud Function, which runs business logic and stores its
result to a new node in the Realtime Database. The newly written
result data is then pushed automatically to the app.




I understand that instead of making a request and expecting a request, they followed the following pattern:




  1. Write to real-time database

  2. The write trigger an action

  3. The action triggers some logic and function

  4. The function writes data back to the database

  5. The listener on the app gets a notification about the data written on 4.

  6. App updates UI or takes whatever action.


Hamilton app followed this pattern when someone enters the competition for a ticket. My main concern with the pattern is that if the connection is offline, we won't get results and at the same time we won't get an error. The changes will be updated locally and firebase will update the next time there is a connection, which will make things messy, as the user is expecting a result.



I was wondering if there is an easy way or a pattern to follow, so we will get an error and display it.



The first solution that comes to my mind is to somehow add a time on the save operation. If the save is not done on the live database within x seconds then we display an error. At the same time, we will also need a timeout on the reply. So if we do not get a reply within x seconds we display something to the user.



I hope I am not confused as I did not understand the pattern well. I struggled with the title, so if anyone can improve it, please be my guest.










share|improve this question














The following quote is taken from Google Developer Blog. https://developers.googleblog.com/2017/08/hamilton-app-takes-stage.html




For example, when someone enters the lottery, the app first writes
data to specific nodes in Realtime Database and the database's
security rules help to ensure that the data is valid. The write
triggers a Cloud Function, which runs business logic and stores its
result to a new node in the Realtime Database. The newly written
result data is then pushed automatically to the app.




I understand that instead of making a request and expecting a request, they followed the following pattern:




  1. Write to real-time database

  2. The write trigger an action

  3. The action triggers some logic and function

  4. The function writes data back to the database

  5. The listener on the app gets a notification about the data written on 4.

  6. App updates UI or takes whatever action.


Hamilton app followed this pattern when someone enters the competition for a ticket. My main concern with the pattern is that if the connection is offline, we won't get results and at the same time we won't get an error. The changes will be updated locally and firebase will update the next time there is a connection, which will make things messy, as the user is expecting a result.



I was wondering if there is an easy way or a pattern to follow, so we will get an error and display it.



The first solution that comes to my mind is to somehow add a time on the save operation. If the save is not done on the live database within x seconds then we display an error. At the same time, we will also need a timeout on the reply. So if we do not get a reply within x seconds we display something to the user.



I hope I am not confused as I did not understand the pattern well. I struggled with the title, so if anyone can improve it, please be my guest.







firebase dart flutter google-developer-tools






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 11 '18 at 8:11









zirinispzirinisp

6,00832634




6,00832634













  • Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

    – Swift
    Jun 3 '18 at 19:43











  • Unfortunately not. Can you please upvote so it get a bit more attention.

    – zirinisp
    Jun 5 '18 at 10:59



















  • Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

    – Swift
    Jun 3 '18 at 19:43











  • Unfortunately not. Can you please upvote so it get a bit more attention.

    – zirinisp
    Jun 5 '18 at 10:59

















Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

– Swift
Jun 3 '18 at 19:43





Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it out

– Swift
Jun 3 '18 at 19:43













Unfortunately not. Can you please upvote so it get a bit more attention.

– zirinisp
Jun 5 '18 at 10:59





Unfortunately not. Can you please upvote so it get a bit more attention.

– zirinisp
Jun 5 '18 at 10:59












1 Answer
1






active

oldest

votes


















0














Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online.
However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.






share|improve this answer























    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%2f50287887%2foffline-usage-flutter-hamilton-app-architecture-write-to-node-and-expect-cloud%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









    0














    Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online.
    However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.






    share|improve this answer




























      0














      Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online.
      However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.






      share|improve this answer


























        0












        0








        0







        Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online.
        However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.






        share|improve this answer













        Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online.
        However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 19:42









        Dario IelardiDario Ielardi

        181112




        181112






























            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%2f50287887%2foffline-usage-flutter-hamilton-app-architecture-write-to-node-and-expect-cloud%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

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks