Akita: How difficult is to create an offline-first app?

Created on 29 Sep 2020  路  13Comments  路  Source: datorama/akita

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

I only discovered this project today.

Congratulations for this great job!

In your opinion, how difficult is it to create an offline-first Web/Desktop/Native application with this project?

Anything that respects these rules?

question

Most helpful comment

Hey @frederikhors, have you checked Pouchdb? It basically is a solution for your problem. However, you will need to have a backend running CouchDB our that implements CouchDB API.

Akita is a state management library.
It basically tracks the entities that exist and what happened to get them to a specific state.
Using localStorage or other browser storages, you can save the "final" state of your app so, when opening it again, you dont have to fetch all that data you previously had.

With that being said, and complement what @NetanelBasal said, you can use Akita to BUILD your own solution.
The simplest way to do it is to have a modified boolean field on your model.
So, you can have a service that queries Akita for entities marked as modified and push them to the backend. And get the backend to perform anything you need...

For sure you can do something more advanced, something like a CQRS + event system - but that will need you to work on the backend.

Why Im telling you all this:
Im using Akita on a project and using it offline, doing the "simplest" approach. The biggest downside is the overhead. You never know what you need to get back from the backend, what was deleted, what the user lost permissions... So, we need to download everything again and again and again...
For the sake of quickly delivering an offline first solution, it works. But then you will want to move to something with less overhead.
Which means building something that forces the app to do validations on timestamps or versioning, as well as the backend, so the app can send and request only the required data (thus the CQRS + event system pattern).
It is not easy, but doable.

All 13 comments

This is a general question. I can't answer this without knowing what you need to do. Sorry, but I don't have time to dive into the article.

We are evaluating your project because we want to build a CRM-like that must have all the data and a 100% offline CRUD with synchronization once online.

I cannot understand if we can achieve this with your project.

Some of the questions in the article:

  1. Are conflicts handled? How?

  2. How much data does the client need to store to fully replicate (full offline data access & editing)?

  3. Does it require all data to live in memory, or can it work with mostly-persisted data? (such that large datasets are usable)

  4. Does it correctly handle working on multiple tabs in the same browser session?

Akita is a state management solution. You can persist the data to web storage. You can keep browser tabs in sync using localStorage.

Anything else you'll have to manage yourself

Thanks.

It would be amazing to sync state from browser to server just to handle offline situations.

And I'm not talking about conflicts for now (I don't care at this stage, I can use "last writer wins" or handle the error in the server and communicate it to the single client).

What do you suggest as an effective sync system to any backend?

I'm not sure what you mean by "an effective sync system to any backend"? Can you elaborate?

Hey @frederikhors, have you checked Pouchdb? It basically is a solution for your problem. However, you will need to have a backend running CouchDB our that implements CouchDB API.

Akita is a state management library.
It basically tracks the entities that exist and what happened to get them to a specific state.
Using localStorage or other browser storages, you can save the "final" state of your app so, when opening it again, you dont have to fetch all that data you previously had.

With that being said, and complement what @NetanelBasal said, you can use Akita to BUILD your own solution.
The simplest way to do it is to have a modified boolean field on your model.
So, you can have a service that queries Akita for entities marked as modified and push them to the backend. And get the backend to perform anything you need...

For sure you can do something more advanced, something like a CQRS + event system - but that will need you to work on the backend.

Why Im telling you all this:
Im using Akita on a project and using it offline, doing the "simplest" approach. The biggest downside is the overhead. You never know what you need to get back from the backend, what was deleted, what the user lost permissions... So, we need to download everything again and again and again...
For the sake of quickly delivering an offline first solution, it works. But then you will want to move to something with less overhead.
Which means building something that forces the app to do validations on timestamps or versioning, as well as the backend, so the app can send and request only the required data (thus the CQRS + event system pattern).
It is not easy, but doable.

I'm not sure what you mean by "an effective sync system to any backend"? Can you elaborate?

Something to synchronize the operations Akita saves in the browser once the connection with the server is restored.

We don't have this functionality. Can you give me an example of how you imagine a JSON representation of this?

Something to synchronize the operations Akita saves in the browser once the connection with the server is restored.

May be you can use a service-worker for this: https://developers.google.com/web/ilt/pwa/introduction-to-service-worker

When your user performs an action, add the result of the action to Akita and send the HTTP request through the service-worker. The service worker, on the other hand, would listen to successful requests and push the results back to Akita.

I am implementing something similar using Service Workers, IndexedDB and Akita ngEntityStore

@mattbodman I know this is not the scope for a/this github issue, but Id love to read about how you guys are implementing it, challenges and victories.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brgrz picture brgrz  路  4Comments

stephencarr picture stephencarr  路  4Comments

eitanfr picture eitanfr  路  4Comments

zvnt picture zvnt  路  6Comments

hoisel picture hoisel  路  5Comments