Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to build offline-first mobile apps using AWS AppSync?

I'd like to use AWS AppSync for mobile development (Android/iOS) but I’m not sure about its offline capabilities.

According to the documentation the data will be accessible while being offline and synced automatically if the client gets online again. But I can't find any information about if the app client needs to connect to AWS first, before using AppSync to create and modify offline data.

I'm not familiar with the underlying technologies of AppSync (e.g. GraphQL) and I don't have access to the public preview version to test it myself.

I would like to enable privacy-sensitive users to use an app without connecting to AWS while still being able to use AppSync as an offline database. Only if a user later decides to use backup/sync data across devices he or she can opt-in to connect to AWS.

Will this use case be possible with AWS AppSync?

Without using any other local storage (like SharedPreferences, SQLite, Realm, etc.)

like image 409
Steffen Avatar asked Dec 08 '17 11:12

Steffen


People also ask

What is the difference between AppSync and amplify?

AWS Amplify can integrate with any GraphQL provider to perform queries and real-time data subscriptions via it's easy to use GraphQL client. AWS AppSync extends GraphQL's capabilities even more by offering enterprise-level security, real-time data synchronization, and orchestration of backend data resources.

Is AppSync scalable?

AWS AppSync is a serverless solution that allows you to build scalable real-time applications and take advantage of the optimized GraphQL layer at the same time.

Why should I use AppSync?

So that's it, here are five glorious reasons to consider using AppSync instead of API Gateway for your next project: it supports Cognito group-based authorization natively. request and response validation is built into how GraphQL works. its WebSockets implementation is both easy to use and highly scalable.

What type of API is used in AppSync service?

A single data API AWS AppSync securely connects your GraphQL API to data sources like AWS DynamoDB, RDS, OpenSearch, and Lambda. Adding caches to improve performance, authentication to secure your data, and client-side data stores that keep off-line clients in sync are just as easy.


1 Answers

It should be possible with Firestore, AWS AppSync or your own Backend solution. Any approach you use, you will control when you want to start saving/syncing things online.

You need to handle all this while designing this app. Suggested approach

Let's take example of simple ToDo app

  • I will let User add & save Todos in app

  • All this data will be persisted on disk(using SQLLITE, Preferences or File etc.)

  • If User does clear data or reinstall app, all this data is lost
  • If User wants to go premium, I will let him sync this data with my Backend solution(any one of above-mentioned solution)

Example implementation using Android Shared preference as local storage

public void saveLocalTodo(String title, String details) {
    ArrayList<Todo> todos;
    Todo todo = new Todo(title, details);
    String listOfTodo = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodo == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodo, new TypeToken<ArrayList<Todo>>() {
        }.getType());

    //save at 0th position, recent should always come first
    todos.add(0, todo);
    sharedPreference.edit().putString(TODOS_LIST, gson.toJson(todos)).apply();
}

public ArrayList<Todo> getLocalTodos() {
    ArrayList<Todo> todos;
    String listOfTodos = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodos == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodos, new TypeToken<ArrayList<Todo>>() {
        }.getType());
    return todos;
}

public void saveOnBackend() {
    // Connect to Backend solution

    // Get all local todos from preference
    // Save all at once in batches

    //OR

    // Get all local todos from preference
    // Save one by one
}
like image 77
Akhil Avatar answered Oct 21 '22 13:10

Akhil