When you determine how to update a KiiObject on Kii Cloud from the client, you can choose from several methods according to your scenarios.
Kii Cloud accepts combinations of the following two options:
You can choose how Kii Cloud updates existing key-value pairs in a JSON document on the server with key-value pairs that are sent from the client.
- Full update: This method completely overwrites the data on the server with the data from the client. Key-value pairs that are not included in the client request will be deleted from the server.
- Partial update: This method merges the data on the server with that from the client and overwrites the data on the server. Key-value pairs that are not included in the client request will remain on the server.
The figure below shows how the two updating methods work. The data from the client does not contain the
gender key. The full update method deletes the key while the partial update method keeps it.
Use these methods properly depending on the circumstances. The full update method is appropriate for improving the communication performance because it sends only a subset of large data. On the other hand, the partial update method helps to clarify what will remain on the server after data is updated because it completely overwrites target data.
With the overwrite check feature, you can use a technique known as optimistic locking and ensure data consistency when multiple clients simultaneously update the same KiiObject. You can also disable the overwrite check.
Suppose the overwrite check is enabled. When a client downloads a KiiObject from Kii Cloud and then another client updates the KiiObject, a subsequent update from the first client will be rejected.
The figure below shows how the overwrite check works. Client 1 and Client 2 download and update the same KiiObject almost simultaneously. The update request from Client 2 is rejected because Client 1 has updated the KiiObject.
If an error is returned, the mobile app needs to download and update target data again. It might be more appropriate for some services to send a notification about a conflict.
You can prevent unexpected conflicts by enabling the overwrite check for buckets in the application scope and group scopes because multiple clients are likely to write to such buckets.
You can simplify the update process by disabling the overwrite check for buckets that are not likely to have update conflicts, for example, in user scopes.
By utilizing optimistic locking, Kii Cloud ensures data consistency as well as scalability and performance in the data updating process. User growth does not affect the performance because Kii Cloud does not use exclusive locking.
- The tutorial with a sample app Kii Balance includes tips for designing updating processes in a real mobile app. See Data Consistency when you work on data design.