<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>libJoTS: JSON That Syncs!?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Amos Brocco</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Patrick Ceppi</string-name>
          <email>patrick.ceppig@supsi.ch</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Lorenzo Sinigaglia</string-name>
          <email>lorenzo@banana.ch</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Banana.ch SA</institution>
          ,
          <addr-line>Lugano</addr-line>
          ,
          <country country="CH">Switzerland</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Department of Innovative Technologies, SUPSI</institution>
          ,
          <addr-line>Manno</addr-line>
          ,
          <country country="CH">Switzerland</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we present libJoTS, a C/C++ library that provides asynchronous o ine replication of arbitrary JSON data with a minimal footprint. The primary use case for this library is to easily replicate changes made to a JSON le by di erent users. The replication process is based on multi-version concurrency control (MVCC) to ensure non-destructive con ict management, but in contrast to other popular databases, libJoTS has no runtime dependencies, supports hierarchical documents with nested objects, and stores all synchronizable data into a le. The library is self-contained, and provides a simple API for C/C++ programs as well as bindings for other languages, such as Java and Python. As such it can be easily linked into any application, allowing end-users to replicate changes to data asynchronously and ofine. By using les, data sharing between users does not depend on any speci c technology, and can be achieved either with an online le-sharing service or o ine, thus ensuring full control on data privacy.</p>
      </abstract>
      <kwd-group>
        <kwd>JSON</kwd>
        <kwd>MVCC</kwd>
        <kwd>Data Synchronization</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Nowadays, many popular applications that once ran natively (o ine) on
personal computers are being pushed to the cloud. At user level, one of the most
signi cant improvements brought by cloud applications is the ability to easily
share data with other people and to work online in a collaborative fashion. In this
regard, replication protocols [1{3] are the cornerstone of those multi-user
applications, allowing updates made to each replica to be consistently merged together.
Replication can be either synchronous or asynchronous. With synchronous
replication, often simply referred to as synchronization, there is a continuous ow
of information that propagates changes to all replicas: as soon as new data is
being created or updated, data is (atomically) replicated to all remote copies.
With asynchronous replication, changes are not propagated in realtime, and
the system might even tolerate temporary divergence between replicas. While
the synchronous approach ensures that each replica always contains the same
data, the overall performance and availability is a ected by network availability,
reliability and speed. Concerning cloud applications, developers are currently
advised to develop software that is able to work even when there is no
connectivity: in this context asynchronous replication mechanisms play an important
role in allowing users to work on local data, while enabling synchronization with
a remote server when online. Beside technical aspects, sharing data on the cloud
and storing potentially sensitive data on someone else's computer, introduce
privacy, security and legal concerns [
        <xref ref-type="bibr" rid="ref4 ref5">4, 5</xref>
        ]. In this regard, the user should be able
to retain as much control as possible on his/her information, either by relying
on o ine applications and local le storage, or by using connected applications
that o er an open or generic synchronization layer that does not depend on any
vendor-speci c cloud API. The rst approach allows for selective disclosure of
information (the user decides whom to send his/her information to), but
typically makes synchronization between di erent versions of the same data di cult.
The library presented in this paper, called libJoTS, tackles this issue by
implementing an o ine asynchronous replication mechanism for arbitrary JSON data.
libJoTS allows any native application to store data in a synchronizable format;
moreover because data is always stored as a le on disk, remote sharing can also
be performed using any means, like e-mail or le-hosting platforms. Finally,
synchronizable les can be easily encrypted (using either symmetric or asymmetric
algorithms) and/or digitally signed to prove that data was not altered.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Related Work</title>
      <p>
        Data replication and synchronization technologies are the cornerstone of
distributed storage systems and cloud-based content editing applications (for
example Google Docs™). Although there exist di erent algorithms and protocols
to keep data synchronized [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], we restrict our focus to asynchronous
replication, which represents the closest concept to the proposed solution. With
asynchronous replication, updates on the master (or source) storage are not copied
immediately to a secondary storage (or target), but can be delayed to a later
time. Such an approach gives up on strict consistency and update timeliness
across the network, while supporting the development of o ine rst solutions,
which can operate even without a permanent connection between clients and
servers on the network. In this regard, a well-known technology is CouchDB [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], a
document-oriented NoSQL database which supports multi-master asynchronous
replication: each instance can be independently updated, and changes can be
replicated between any instance. Unfortunately, CouchDB is not suited for
deployment on mobile devices or the web, therefore similar databases that share
https://developer.chrome.com/apps/o ine apps
the same replication protocol have been developed (for example, Couchbase Lite
or PouchDB). With those solutions it is possible to build applications that can
operate on a local database while o ine and asynchronously replicate changes
to another peer when a network connection becomes available. With libJoTS
we aim to provide transparent o ine data replication, by generating a
synchronizable le which can be stored and exchanged through any communication
channel. Such a synchronizable le might also be signed and/or encrypted,
allowing for accountability and/or con dentiality of the data being exchanged. In
contrast to a di /patch [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] solution (which also work on les), libJoTS is
tailored for semi-structured data in JSON format and ensures that the structure
is maintained in the merged document. Data is versioned and each revision is
stored directly into the le, allowing for historical data retrieval. Like CouchDB,
con ict management is based on MultiVersion Concurrency Control (MVCC):
accordingly, replication can be performed among di erent synchronizable les in
no speci c order, without compromising the structure of the underlying data.
Although there exist comparison tools expressly conceived for JSON data (see
for example, RFC6902), those solutions do not maintain an historical record
of all versions of the data and might still require user intervention to ensure
consistency in the event of concurrent con icting modi cations. In contrast to
some of the previously cited solutions, libJoTS does not require the source data
to be decomposed into a collection of documents, and the library can be easily
integrated into desktop or mobile application, being self-contained and written
in C++ (with a C API and bindings for other languages, currently Java and
Python, and the possibility of targeting WebAssembly in the future).
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Use Cases</title>
      <p>With libJoTS we aim at supporting the development of distributed applications
that rely on synchronized data without the need for a dedicated server or a
speci c cloud platform, by enabling information sharing regardless of the type of
communication channel (for example, shared folder, e-mail or portable storage).
Each user is in control of the data and can decide when to share its own version
or merge changes from other users. In the following two use cases are presented.
3.1</p>
      <sec id="sec-3-1">
        <title>O ine rst application</title>
        <p>We consider a desktop or mobile application that lets users edit documents o ine
on their device and later share their work with other people. User A produces
the rst version of document X; this version is sent to users B and C through
a cloud-based le sharing service. Both user A, B and C make their changes to
the document. Subsequently, user B sends its own updated version to User A by
email, who can then merge the changes made by B in its copy. At the same time
https://www.couchbase.com
https://pouchdb.com
https://tools.ietf.org/html/rfc6902
user C sends its own version to B by email. User B integrates the changes made
by C, merges incoming updates from A and then forwards its nal version of the
document to C (Figure 1). Users can perform arbitrary editing and replication,
and the process can be scaled to an even larger group of users. Moreover, each
user can store copies of synchronizable les for archival or backup purposes:
those le can be later processed by the library in order to restore data in the
application's own format or to peform synchronization.
A common problem in distributed systems is con guration management.
Conguration updates need to be replicated from a central server to a multitude of
nodes. By means of synchronizable JSON les, libJoTS can be used to create
mergeable con guration updates: because con ict handling is non-destructive,
local changes are preserved while updates to global settings can be seamlessly
integrated. Con guration updates can also be stored on disk to be merged later,
and the authenticity of an update can be veri ed by means digital signatures.
4</p>
        <p>libJoTS Data Model
The data model used by libJoTS is based on JSON documents. Similar to
CouchDB the basic unit of replication is a JSON object: the replication
algorithm compares two collections of JSON objects and determines the ones missing
on each collection. Whereas, CouchDB and other document-oriented databases
(like PouchDB) require the application to organize its data into separate JSON
objects, libJoTS accepts either a collection of separate objects or an arbitrary
JSON document (with a nested hierarchy of objects), and can seamlessly
replicate their changes. Therefore, from an application's point of view, if JSON is
already employed as a data interchange format, little to no change is required
to make use of the synchronization capabilities of the library. The proposed
approach for dealing with hierarchical JSON documents is to automatically
transform an arbitrary input (for example, Listing 1.1) into a collection of objects
which can be synchronized independently.
{" data ":{" transactions ":[
{" _id ":"391...32 c" ," currency ":" CHF " ," value ":22412 ," from ":"13465 -45566" ,
" to ":"34655 -67554"}]} ," info ":{" txcount ":1}}</p>
        <sec id="sec-3-1-1">
          <title>Listing 1.1. Sample application JSON (un attened, version V1)</title>
          <p>The output of such a data transformation (Listing 1.2) is a attened
collection where array of objects from the input document have been replaced by a
string reference, and their contents have been promoted to rst-level objects.
Optionally, nested objects can be promoted too.
[{" _id ":"391...32 c" ," currency ":"! CHF " ," from ":"!13465 -45566" ," to
":"!34655 -67554" ," value ":22412} ,{" _id ":" @123 ...8 b1 -u" ,"s ":["391473 a1 - bb89
-4 dbf - af93 -7 a8cc1ebc32c "]} ,{" _id ":" root " ," data ":{" transactions ":" @123 ...8
b1 "} ," info ":{" txcount ":1}}]</p>
        </sec>
        <sec id="sec-3-1-2">
          <title>Listing 1.2. Flattened collection of JSON documents corresponding to Listing 1.1.</title>
        </sec>
        <sec id="sec-3-1-3">
          <title>Hash values (SHA-256) have been ellipsized for clarity.</title>
          <p>
            We call this procedure attening : each promoted object is associated with a
unique identi er, which can be either created using rules speci ed by the user
or automatically generated by the library using a hash algorithm such as
SHA256 [
            <xref ref-type="bibr" rid="ref7">7</xref>
            ], xxHash or BLAKE2. The attening transformation is non-destructive
and can be undone to restore the original un attened hierarchical structure. To
recover the order of the elements inside attened arrays, we generate ordering
documents with a list of identi ers which belong to the corresponding array in the
un attened JSON document. Listing 1.2 illustrates an ordering document
(referenced by the @123...8b1-u identi er). To prevent the synchronization process
from changing the relative order of the elements (as chosen by di erent users),
ordering documents can be tied to speci c user/instance identi ers: hence each
user can synchronize data without losing their ordering. Moreover, strings are
escaped using the ' !' character to di erentiate them from references to arrays or
promoted objects.
{" d ":{
"391...32 c ":[" d29 ... d0b "] ,
" @123 ...8 b1 -u ":["3 fc ... e82 "] ,
" root ":[" cc6 ...5 d6 "]} ,
"o ": {
"3 fc ... e82 ":{" s ":["391...32 c "]} ,
" cc6 ...5 d6 ":{" data ":{" transactions ":" @123 ...8 b1 "} ," info ":{" txcount ":1}} ,
" d29 ... d0b ":{" currency ":"! CHF " ," from ":"!13465 -45566" ," to ":"!34655 -67554" ,
" value ":22412}} ,
"r ":" root "}
          </p>
        </sec>
        <sec id="sec-3-1-4">
          <title>Listing 1.3. Synchronizable JSON document corresponding to Listing 1.1.</title>
          <p>4.1</p>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>Synchronizable JSON</title>
        <p>A Synchronizable JSON le contains a attened collection of JSON objects
along with versioning information. Similar to MultiVersion Concurrency Control
(MVCC), concurrent updates and replication never overwrite existing data, but
https://cyan4973.github.io/xxHash
https://blake2.net
simply create a new revision for the concerned objects. The revision string is
computed by hashing the contents of the object. All revisions but the rst one
have an ancestor : for each object, we maintain the history of revisions (also
known as the revision tree), which is stored inside the Synchronizable JSON ).
By consulting the revision tree it is possible to determine the order of each
update and thus the most recent revision (known as the winning revision), which
coincides with the tip of the longest branch of the tree. The Synchronizable JSON
data corresponding to Listing 1.1 is shown in Listing 1.3. The value associated
with the key d (for documents ) is a dictionary of all objects' identi ers and the
corresponding revision trees, whereas the value corresponding to o (for objects)
is a dictionary with the contents of each revisions. Finally, the r key points to
the identi er of the root element (which is needed to reconstruct the original
JSON document).</p>
        <p>
          The replication algorithm implemented in libJoTS merges all changes found
in a source document into a target document. Given two collections of versioned
documents C1 and C2, the replication of C1 to C2 will copy all the documents
and revisions of C1 that are missing in C2. At the same time, the revision tree
for each document will be updated accordingly. If more than one revision shares
the same ancestor a con ict will arise: in that case, a deterministic algorithm
will choose the winning revision based on the longest revision branch and
lexicographical comparison. This algorithm achieves replica convergence and eventual
consistency using MVCC, as in [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ].
{" data ":{" transactions ":[
{" _id ":"391...32 c" ," currency ":" EUR " ," value ":22412 ," from ":"13465 -45566" ,
" to ":"34655 -67554"}]} ," info ":{" txcount ":1}}
        </p>
        <sec id="sec-3-2-1">
          <title>Listing 1.4. Updated JSON document (version 2a)</title>
          <p>{" data ":{" transactions ":[
{" _id ":"391...32 c" ," currency ":" USD " ," value ":22412 ," from ":"13465 -45566" ,
" to ":"34655 -67554"}]} ," info ":{" txcount ":1}}</p>
        </sec>
        <sec id="sec-3-2-2">
          <title>Listing 1.5. Updated JSON document (version 2b)</title>
          <p>As an example of the whole replication process, consider the two updated
documents in Listings 1.4 and 1.5. Both have been produced starting from version
1: in version 2a, the value associated with key currency has been changed from
CHF to EUR, in version 2b the value has been changed to USD.</p>
          <p>The corresponding synchronizable documents can be merged together to
produce a new version (Listing 1.6). Both the data contained in version 2a and in
version 2b are present in the resulting document, and the revision tree for 391...32c
contains a reference to both revisions. The deterministic con ict resolution
algorithm will choose either one of the revisions as winner (in this example, the
result corresponds to Listing 1.5).
{" d ":{
"391...32 c ":[" d29 ... d0b " ,["151...4 cf_d295e90 " ,"8 be ...7 cb_d295e90 "]] ,
" @123 ...8 b1 -u ":["3 fc ... e82 "] ,
" root ":[" cc6 ...5 d6 "]} ,
"o ":{
"151...4 cf ":{" currency ":"! EUR " ," from ":"!13465 -45566" ," to ":"!34655 -67554" ,
" value ":22412} ,</p>
          <p>Because each revision is kept inside the Synchronizable JSON le, the more
the data is updated, the bigger the size of the le becomes. This problem can
be mitigated by enabling the built-in compression of the Synchronizable JSON
le. To further limit this growth, we make use of pruning to delete the value
associated with old revisions. More speci cally, the pruning operation removes
stale (i.e. non-winning) branches in each revision tree and deletes unreferenced
revision objects. The client application can select the depth of the pruning
operation in order to maintain an historical record of previous data values (for
example, to provide an undo functionality).
5</p>
          <p>API
To support the basic operations related to Synchronizable JSON les, the public
API provides four core functions :
{ sync json update updates or creates a Synchronizable JSON document
from an arbitrary JSON object (in the application's own format). Since
the library is stateless, the Synchronizable JSON object must be stored (i.e.
saved to a le) by the application itself.
{ sync json read reads a Synchronizable JSON document and converts it
back into an application-compatible JSON document.
{ sync json replicate replicates changes from a source Synchronizable JSON
document to a target one.
{ sync json prune removes historical information (i.e. old revisions) from a</p>
          <p>Synchronizable JSON document.
5.1</p>
        </sec>
      </sec>
      <sec id="sec-3-3">
        <title>O ine Work ows</title>
        <p>To better understand how the library is meant to be used by an application,
in the following we present the expected work ow covering both the creation of
Synchronizable JSON documents and o ine replication of changes.</p>
      </sec>
      <sec id="sec-3-4">
        <title>Updating a Synchronizable JSON le To generate the rst version of a Syn</title>
        <p>chronizable JSON document, the application needs to provide the input JSON
le to the sync json update. The output document contains all synchronization
information required for subsequent replications and can be shared with other</p>
        <sec id="sec-3-4-1">
          <title>Additional functions for manipulating Synchronizable JSON are also available.</title>
          <p>users. In order to update a Synchronizable JSON it is necessary to provide a
Synchronizable JSON to the sync json update function, along with the updated
JSON data. In a distributed scenario several Synchronizable JSON documents
can be updated in parallel, independently from each other, without loosing the
ability to later replicate their changes. In this regard, each document represents
a di erent branch in the version tree.</p>
        </sec>
      </sec>
      <sec id="sec-3-5">
        <title>Reading a Synchronizable JSON le Synchronizable JSON can be con</title>
        <p>verted back to the application's own format using the sync json read function.
By means of additional procedures provided by the library, speci c revisions of
the data can also be obtained.</p>
        <p>Replicating a Synchronizable JSON le Using the sync json replicate
function it is possible to replicate changes made to a source Syncronizable JSON
le into a target le: we refer to this process as o ine replication. Because each
element of the document is versioned, the replication process does not lose any
data (non-destructive con ict management). The user can also query for the
di erences between the new and the old version, as well as con icting data.
5.2</p>
      </sec>
      <sec id="sec-3-6">
        <title>Online Replication Work ows</title>
        <p>Provided that both the source and the target peers are online at the same time
(or are able to directly communicate), it is possible to optimize the replication
process by sending only bits of modi ed data. Although not directly implemented
by the library, two approaches are proposed: a di /patch mechanism, and an
interactive replication protocol.</p>
        <p>JSON Patch approach The JSON Patch solution requires a RFC6902
compliant di and patch tool to produce a sequence of operations to apply to a
target JSON le (at version VM) in order to update its structure to be equal to
a source version VN. As mentioned previously, patching the application's JSON
does not provide a robust solution to the replication problem, since data might
be inadvertently overwritten or corrupted due to con icting modi cations;
therefore we consider generating patches against Synchronizable JSON les in order
to maintain the full revision history. The target peer needs to communicate its
version VM of the data to the source peer. The source peer then employs a JSON
di function to produce a patch needed to update VM to VN. Unfortunately,
such an approach makes synchronization di cult (if not impossible) in a
multimaster scenario, where multiple versions of a document with di erent replication
histories arise from concurrent o ine synchronizations made by di erent users:
in this situation patches might not apply cleanly leading to data corruption.</p>
        <sec id="sec-3-6-1">
          <title>Such as https://github.com/nlohmann/json</title>
          <p>Interactive replication protocol If both the source and the target peers are
online, a more e cient replication can be implemented through an interactive
protocol.The source peer sends an o er message to the target, containing a list
of document identi ers and their associated winning revision. The target replies
with an array of identi ers of documents that are either unknown or whose latest
revision is older than the one proposed by the source. Finally, the source provides
a Synchronizable JSON document with just the missing information. Compared
to the JSON Patch solution, an interactive replication protocol generates more
tra c but does not require the source peer to keep all previous versions of a
document. Moreover, it can replicate changes between di erent branches (i.e.
Synchronizable JSON documents that have a di erent revision history). The
library also provides methods to migrate data to and from CouchDB-compatible
servers, hence replication through another database is also possible.
6</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Benchmarks</title>
      <p>We evaluate the performance of our library by considering a stepwise editing
work ow of a JSON document. The evaluation process begins with version V1
of a simple JSON document containing an array of objects (Listing 1.1). We
subsequently create a new version by performing some changes to the data.
More speci cally, version VN is modi ed to produce version VN+1 as follows: a
new object is added to the transaction array, and the contents of an existing
object (except the id eld) are replaced with new data. Moreover the value
of the eld txcount is updated to re ect the size (number of elements) of the
transaction array. At each step, version VN of the Synchronizable JSON and
version VN+1 of the application JSON are processed by the sync json update
function to produce version VN+1 of the Synchronizable JSON. The resulting
document is pruned to remove all but the latest revision of the internal data. The
last version of the Synchronizable JSON is subsequently replicated on the
secondlast version using sync json replicate, and the replication result is converted
back to the application's own format using sync json read. The execution of
all operations is pro led in order to measure the required time, the maximum
amount of main memory used during the process (maximum RSS), and the
resulting le size (for both the Synchronizable JSON and the application JSON).
The library was con gured to use the SHA-256 hashing algorithm for generating
revision hashes and compression was disabled (unless otherwise speci ed). All
tests were repeated 10 times on a 64-bit Ubuntu Linux machine with an Intel©
Core™ i7-6500U CPU running at 2.50GHz with 16GB or memory. The library
was compiled with gcc version 9.2.1: the actual size of the library is less than
900 KB, with dependencies only against the standard library and the pthreads
library. For comparison, a minimal install of CouchDB 2.3.1 takes about 40 MB,
whereas version 7.1.1 of PouchDB (without JS runtime) is 123 KB.</p>
      <sec id="sec-4-1">
        <title>Results also show the le size using the xxHash algorithm for comparison purposes.</title>
        <p>6.1</p>
        <sec id="sec-4-1-1">
          <title>O ine replication results</title>
          <p>As shown in Figure 2, the time required to process JSON data using the library
grows linearly with respect to the size of the le. In this regard, we note that
the size of the nal version of the le (containing a total of 1000 sub-objects) is
about 133 KB, and that the total includes also the time spent loading the le
from disk. As expected, reading Synchronizable JSON back into the application's
own format is the least expensive operation, whereas updating or replicating data
takes almost the same time. The growth in each graph is marked by a series of
steps due to the allocation of memory for the internal structures of the library.</p>
          <p>
            Additional testing allowed us to assess the scalability of the replication
algorithm with respect to the input le size: on the same hardware, generating a
Synchronizable JSON document from a 65.5 MB le with 335,389 sub-objects
requires about 18 seconds (with the attening process taking about 80% of the
time), and produces a 110 MB output le. Merging two Synchronizable JSON
les of such a size (where one le contains 479 updated objects with respect
to the other) takes about 12 seconds, while converting the result back to the
application's un attened format requires about 10 seconds. With large les the
total cost is clearly dominated by parsing the input JSON, which is a known
problem when dealing with this format [
            <xref ref-type="bibr" rid="ref9">9</xref>
            ]. Trying to import the same amount
of data into PouchDB (using the bulk docs interface) freezes the program.
          </p>
          <p>Concerning memory allocation, Figure 3 illustrates the memory required for
updating, reading and replicating data using the library. In each case the growth
follows the increase in the size of the input document. Replication requires the
largest amount of memory, since data from both input les need to be stored at
the same time; as expected, reading takes the least memory amount.
Unfortunately JSON parsing is memory intensive, and very high requirements are to be
expected when dealing with large les: with the previously mentionend 110 MB
Synchronizable JSON les, replication requires almost 3 GB of memory.</p>
          <p>
            Figure 4 takes into consideration the cost for o ine synchronization, by
comparing the le size of both the original JSON le (application JSON) and
Synchronizable JSON. The graph also shows the di erence between two hashing
algorithms (SHA-256 and xxHash) which can be used to generate object and
revision identi ers. Even though pruning was used to limit the amount of historical
information kept with the le, Synchronizable JSON clearly takes more space
on disk compared to application JSON, because of the additional information
required to support o ine replication (namely, revision trees). It is interesting
to note that xxHash allows for more compact synchronizable les compared to
SHA-256, because it generates 64 bit hashes instead of 256 bit ones. If
Synchronizable JSON les are not meant to be processed outside the library, built-in
compression (based on the de ate [
            <xref ref-type="bibr" rid="ref11">11</xref>
            ] algorithm) can be enabled to further
reduce the size of the le by about 40%. With respect to the work ow involving
other databases with support for replication, the size of Synchronizable JSON is
typically smaller: the on-disk space taken by PouchDB for the same information
(stored as a structured log) is 1.3 Megabytes.
6.2
          </p>
        </sec>
        <sec id="sec-4-1-2">
          <title>Online replication results</title>
          <p>In order to asses the bene t of online replication (either using the di /patch
approach or the interactive replication protocol ) we repeated the experiment
discussed in the previous section assuming that new versions are generated on
a source peer while measuring the amount of data that needs to be sent to a
target peer in order to keep both replicas synchronized.</p>
          <p>Fig. 5. Amount of exchanged data vs
replication approach.</p>
          <p>As shown in Figure 5, exchanging the full synchronizable JSON le consumes
more bandwith than online protocols; the tra c generated using the RFC6902
approach is also signi cantly lower than the interactive protocol, because only
a small amount of information needs to be sent to the target. However, such an
approach would not work in a multi-master scenario, where multiple branches
need to be synchronized. Although not shown in the graph, the resulting tra c
is not meaningfully a ected by the hashing algorithm, with xxHash producing
the same amount of data as SHA-256.
7</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Conclusions</title>
      <p>In this paper, we presented libJoTS, a C/C++ library that provides
asynchronous o ine replication of arbitrary JSON data. The primary use case is
to easily replicate changes asynchronously and independently made to a JSON
document by di erent users. The replication process is based on multi-version
concurrency control (MVCC) to ensure non-destructive con ict management.
The proposed approach draws inspiration from popular document databases
with built-in support for replication, but provides a standalone lightweight
solution targeting o ine replication of small to moderately sized JSON documents.
Synchronizable JSON les can be stored on disk, digitally signed and exchanged
with any type of communication technology in order to be later merged on a
remote system. The API focuses on an o ine- rst approach, allowing for
exchanging synchronizable les using any technology, but also enables online replication
using a simple protocol. The library, which we plan to release in the forthcoming
months, is self-contained and can be easily integrated into any desktop or mobile
application. Future work will focus on implementing an on-disk storage back-end
to reduce memory usage (at the expense of processing time), and abstractions
to ease integration with cloud based le sharing platforms.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Souri</surname>
            , Alireza and Pashazadeh, Saeid and
            <given-names>Habibizad</given-names>
          </string-name>
          <string-name>
            <surname>Navin</surname>
          </string-name>
          , Ahmad.
          <source>Consistency of Data Replication Protocols in Database Systems: A Review</source>
          .
          <source>International Journal on Information Theory (IJIT)</source>
          .
          <volume>3</volume>
          .
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Vidal</given-names>
            <surname>Martins</surname>
          </string-name>
          , Esther Pacitti,
          <string-name>
            <given-names>Patrick</given-names>
            <surname>Valduriez</surname>
          </string-name>
          .
          <article-title>Survey of data replication in P2P systems</article-title>
          . RR-6083, INRIA.
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Apache</given-names>
            <surname>Software</surname>
          </string-name>
          <string-name>
            <surname>Foundation</surname>
          </string-name>
          ,
          <source>CouchDB Replication Protocol, version 3, retrieved February 27</source>
          .
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Sen</surname>
          </string-name>
          , Jaydip.
          <source>Security and Privacy Issues in Cloud Computing</source>
          .
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Paul</given-names>
            <surname>Voigt</surname>
          </string-name>
          and
          <article-title>Axel von dem Bussche. The EU General Data Protection Regulation (Gdpr): A Practical Guide (1st ed</article-title>
          .). Springer Publishing Company, Incorporated.
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>CouchDB</given-names>
            <surname>Team</surname>
          </string-name>
          , CouchDB
          <volume>2</volume>
          .0 Reference Manual, Samurai Media Limited.
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Handschuh</surname>
          </string-name>
          , Helena. SHA-0, SHA-1, SHA-2
          <article-title>(Secure Hash Algorithm).</article-title>
          .
          <source>In Encyclopedia of Cryptography and Security (2nd Ed.)</source>
          , edited by Henk
          <string-name>
            <surname>C. A. van Tilborg</surname>
          </string-name>
          and
          <string-name>
            <surname>Sushil Jajodia</surname>
          </string-name>
          , Springer,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Ezechiel</surname>
          </string-name>
          , Katembo and Kant, Shri and Agarwal, Ruchi..
          <source>Analysis of database replication protocols</source>
          .
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Langdale</surname>
          </string-name>
          , Geo and Lemire, Daniel. Parsing Gigabytes of JSON per Second.
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>MacKenzie</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Eggert</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Stallman</surname>
          </string-name>
          , R..
          <article-title>Comparing and Merging Files with GNU di and patch</article-title>
          .
          <source>Network Theory Ltd</source>
          ,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>P.</given-names>
            <surname>Deutsch.</surname>
          </string-name>
          <article-title>RFC1951: DEFLATE Compressed Data Format Speci cation version 1.3</article-title>
          . RFC Editor, USA.
          <year>1996</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>