Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I support offline mode using DynamoDB and iOS?

This is a little bit of Parse fallout.

I'm moving an app to use DynamoDB but it doesn't seem to support any kind of offline mode.

How should I do this?

I'd like to use Realm but I'll end up having to manage synchronising and object <-> noSQL. Should I use a flag on a row to indicate it has been synced?

Should I try and keep the row flat like it is in Dynamo?

I don't think the sync part of Cognito is applicable here.

like image 625
Scott McKenzie Avatar asked Jan 29 '16 08:01

Scott McKenzie


People also ask

Can I use DynamoDB locally?

Having this local version helps you save on throughput, data storage, and data transfer fees. In addition, you don't need an internet connection while you develop your application. DynamoDB Local is available as a download (requires JRE), as an Apache Maven dependency, or as a Docker image.

Which data models are supported by DynamoDB?

DynamoDB supports both key-value and document data models. This enables DynamoDB to have a flexible schema, so each row can have any number of columns at any point in time.

When should you not use DynamoDB?

Even though the solution has many benefits, one of the major drawbacks is that the solution lacks an on-premise deployment model and is only available on the AWS cloud. This limitation does not allow users to use DynamoDB for applications that require an on-premise database.

What supports DynamoDB?

DynamoDB offers built-in security, continuous backups, automated multi-Region replication, in-memory caching, and data import and export tools.


1 Answers

I haven't used DynamoDB before, but I just read through the iOS documentation on Amazon's website, and I THINK integrating the two should be possible, and relatively easy.

It looks like you define data models in DynamoDB the same way as Realm: create a subclass of AWSDynamoDBObjectModel and add your properties. As this is the case, as long as you created a Realm Object (or RLMObject in Objective-C) that had the same matching properties, you should (theoretically) be able to simply pass DynamoDB objects directly to Realm to be saved:

let realm = try! Realm()

try! realm.write {
    realm.create(MyRealmSubclass.self, value: MyDynamoDBObject, update: true)
}

Realm is very smart in being able to use KVC to see if any objects passed to it conform to the schema of its model objects and to automatically retrieve and save that information.

(NB: In order for update: to work properly, you'll also need to ensure your objects share a common primary key property as well).

From the sounds of it, if you're looking to then modify the locally saved data in Realm while the app is offline, and then push that modified data the device is back online, then it'll be up to you to convert the Realm model objects back into DynamoDB objects in order to be pushed back up to AWS.

You could certainly add additional properties to the Realm model, such as a boolean hasChanges flag, or a lastModifiedDate date object in order to be able to check that an offline object has changes that need uploading.

Let me know if you need any additional clarification!

(Full disclosure: I work for Realm.)

like image 167
TiM Avatar answered Oct 24 '22 20:10

TiM