Skip to content

SPIKE: design for async dashboard updates #24950

Closed

Description

@severinbeauvais

The Problem

The business dashboard often fetches data before the Filer has finished processing a just-submitted filing, so the dashboard is out of date even though it was just loaded.

Similarly, the business dashboard sometimes fetches some data (eg, business object) that doesn't match other data (eg, ledger) because they are separate fetch calls and their state could have changed between the two calls.

Also, the business dashboard doesn't automatically update to show the latest state when a filing is processed in the background (eg, Change of Addresses, or Involuntary Dissolution, or Expiry of Limited Restoration, or any FE filing).

Example issues:

  • a business that was just dissolved might still display as active in the dashboard
  • a business that was just restored might still display as historical in the dashboard
  • a business that was just frozen might still display as usable in the dashboard
  • a business that was just unfrozen might still display as unusable in the dashboard
  • any filing that was just filed might not display at all in either To Do or Recently Filing History
  • any filing that was just filed might display as "filed and pending" even though it's actually now completed

Refreshing the dashboard (F5) usually syncs up the latest (now-updated) data, but users don't know to do that, or if and when they should do that, and this is not a good user experience.

Activity

  1. added
    Entities Team
    on Dec 13, 2024
  2. severinbeauvais commented on Dec 16, 2024

    @severinbeauvais
    CollaboratorAuthor

    Proposed Solution 1 - polling for changes

    Pros

    • uses REST call -- compatibility for API users
    • simple to understand and simple to implement

    Cons

    • how often should UI poll API to check for changes? maybe every second right after reload, then once a minute?
    • ongoing network calls that do nothing most of the time (if no business data changes)

    Proposed Solution 2 - server event using persistent connection (websockets)

    Pros

    • supports real-time dashboard updates
    • already used for Digital Business Card (in Filings UI + Legal API)

    Cons

    • what's the impact of, maybe 1000, concurrent websocket connections to Legal API / environment?
    • not compatible with existing API / spec
    • how does API know when to check for and send updates - internal timer/polling or watch queue? (more complicated)

    Proposed Solution 3 - gRPC

    Ref: https://grpc.io/

    Pros

    • supports real-time dashboard updates
    • mature and compatible with Python, JS, etc

    Cons

    • unknown extra load on API
    • not compatible with existing API / spec
    • still need a way for client to know when to query, or for server know when to check for and send updates
    • new technology not currently used

    Proposed Solution 4 - Nuxt Data Fetching

    Ref: https://nuxt.com/docs/getting-started/data-fetching

    It does not appear that Nuxt supports streaming (ie, persistent connection), but the useFetch function supports a "watch" option to automatically re-run the fetching function each time other reactive values (eg, a timestamp) change. This might simplify the data reload logic. Ref

    The Nuxt "middleware" could potentially keep the dashboard data up to date from the server side but I'm not sure how that architecture works nor what its impacts are. (Possibly see Server Side Rendering.) Something similar to this may be implemented for the BRD in #25080.

  3. severinbeauvais commented on Dec 24, 2024

    @severinbeauvais
    CollaboratorAuthor

    @hfekete @argush3 @vysakh-menon-aot @leodube-aot @kialj876 @thorwolpert @JazzarKarim @cameron-eyds @seeker25

    Please give me your quick thoughts on the options above. This is something we really should have in place for our Jan 22 directed launch so it needs to be a quick implementation. (We could always improve/change it later.)

    I'm thinking we go with Proposed Solution 1 (polling), because I think it's the easiest one to understand and implement at this time (as it fits cleanly into our existing REST calls). Thoughts? I want a decision by consensus by Jan 2 so we can start implementing something asap.

    (Yes, this could have been a RFC, but it's not. Sorry.)

  4. seeker25 commented on Dec 24, 2024

    @seeker25
    Contributor
    1. January 22nd launch not alot of time
  5. leodube-aot commented on Dec 27, 2024

    @leodube-aot
    Collaborator

    Given the time constraints and simplicity I'm good with solution 1.

  6. argush3 commented on Dec 27, 2024

    @argush3
    Contributor

    yeah, solution 1 sounds good.

    Probably add some kind of exponential back off strategy right after relevant user actions that may update info displayed on UI.

  7. vysakh-menon-aot commented on Dec 27, 2024

    @vysakh-menon-aot
    Contributor

    I am good with Solution 1 as long as we poll only when needed.
    My suggestion is to check if business.lastModified < most_recent_filing.submittedDate then poll else no poll. In this way we don't need a new endpoint. This should handle most of the scenario's.

    Couple of exception to this is if the most_recent_filing is in PENDING or in PAID status

    • PENDING -> PAID will not change lastModified field
    • if most_recent_filing is future effective (will not change lastModified field until the effectiveDate)
  8. argush3 commented on Dec 27, 2024

    @argush3
    Contributor

    @vysakh-menon-aot are you sure business.lastModified is really updated?

  9. vysakh-menon-aot commented on Dec 27, 2024

    @vysakh-menon-aot
    Contributor

    Its not. I created a PR for this now. bcgov/lear#3154

  10. argush3 commented on Dec 27, 2024

    @argush3
    Contributor

    Its not. I created a PR for this now. bcgov/lear#3154

    Awesome!

  11. severinbeauvais commented on Dec 27, 2024

    @severinbeauvais
    CollaboratorAuthor

    Probably add some kind of exponential back off strategy right after relevant user actions that may update info displayed on UI.

    Yes, that's what I thinking of as well. Like every second for the first 10 seconds after loading, then once a minute for the first 10 minutes? Then once an hour from then on?

    My suggestion is to check if business.lastModified < most_recent_filing.submittedDate then poll else no poll. In this way we don't need a new endpoint. This should handle most of the scenario's.

    I haven't decided on this exactly, but I don't want to call the business endpoint often because I think it does a lot of work in the API (eg, computes allowable actions).

    I was thinking that the FIRST call the UI should do is to fetch the "last change timestamp", and then fetch the timestamp again after loading business, tasks, filings, addresses, directors, anything else? If the second timestamp > first timestamp then reload everything; else delay according to backoff algorithm and then poll again..

    An improvement would be to return an object of timestamps (one for each data object), so that the UI could reload just the updated data objects.

    Performance consideration: there could be 1000 concurrent users, meaning up to 1000 calls per second to the Legal API (but due to exponential backoff it would be much less than that).

  12. argush3 commented on Dec 27, 2024

    @argush3
    Contributor

    Yes, that's what I thinking of as well. Like every second for the first 10 seconds after loading, then once a minute for the first 10 minutes? Then once an hour from then on?

    Sounds good to me.

    I haven't decided on this exactly, but I don't want to call the business endpoint often because I think it does a lot of work in the API (eg, computes allowable actions).

    One option is to call the slim version of business endpoint which will need to have the lastModified field added. It bypasses all the heavy checks mostly i think.

    Example GET business slim request:

    GET https://legal-api-dev.apps.silver.devops.gov.bc.ca/api/v2/businesses/BC0883669?slim=true
    
    {
      "business": {
        "adminFreeze": false,
        "alternateNames": [],
        "goodStanding": true,
        "identifier": "BC0883669",
        "inDissolution": false,
        "legalName": "AC BC LTD 2024.nov.5 22.56 - IMPORT_TEST",
        "legalType": "BC",
        "state": "ACTIVE"
      }
    }
  13. severinbeauvais commented on Dec 27, 2024

    @severinbeauvais
    CollaboratorAuthor

    ^^ OK, nice.

    What possible data could change in the background (as a result of a new filing, or something else), and does business.lastModified reflect that?

  14. argush3 commented on Dec 27, 2024

    @argush3
    Contributor

    I don't really know what that field was actually used for as I don't think I saw any code that updates that field besides the initial creation of the business record.

    With the latest PR Vysakh has added basically any filing that gets processed by the filer will update that business.lastModified. Not sure if that is sufficient. There will be some scenarios where you don't need a refresh as no data being displayed on the UI has changed...but I think we can live with that for now?

  15. severinbeauvais commented on Dec 27, 2024

    @severinbeauvais
    CollaboratorAuthor

    Is there any data that could change not as a result of a filing?

    I can't think of any scenario where the data has changed and the UI doesn't need to be refreshed...? But if so then yeah, I think we can live with that.

  16. vysakh-menon-aot commented on Dec 27, 2024

    @vysakh-menon-aot
    Contributor

    We have 1 scenario. Updating BN update for new business

  17. severinbeauvais commented on Jan 2, 2025

    @severinbeauvais
    CollaboratorAuthor

    @OlgaPotiagalova

    A "simple" API solution was implemented that only tracks certain changes to the filings table. This will catch maybe 95% of the issues we've seen. For the following scenarios, the UI will not auto-refresh, so the user will see the old (now-outdated) data:

    • when a business' BN is updated in the background
    • when a To Do item has been filed and then payment completes in the background
    • when a Draft Continuation Authorization is approved by staff (in another session)
    • business comments may be out of date
    • notifications may be out of date

    Should we come up with another way to do this (after MVP possibly) to get 100% functionality? Are you OK with the existing functionality?

  18. seeker25 commented on Jan 3, 2025

    @seeker25
    Contributor

    Performance consideration: there could be 1000 concurrent users, meaning up to 1000 calls per second to the Legal API (but due to exponential backoff it would be much less than that).

    Performance can be improved if LEAR was using block storage on PVC instead of file storage (Openshift default) or alternatively migrating to GCP (even faster database storage there).

  19. severinbeauvais commented on Jan 3, 2025

    @severinbeauvais
    CollaboratorAuthor

    Performance can be improved if LEAR was using block storage on PVC instead of file storage (Openshift default) or alternatively migrating to GCP (even faster database storage there).

    That's good to know. How can we capture this? @argush3 @vysakh-menon-aot @leodube-aot @chenhongjing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Entities Team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions