13
Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria, UPMC-LIP6, Paris, France * Nuno Preguiça NOVA LINCS, DI, FCT, Universidade NOVA de Lisboa, Portugal Sérgio Duarte NOVA LINCS, DI, FCT, Universidade NOVA de Lisboa, Portugal Annette Bieniusa U. of Kaiserslautern, Germany Valter Balegas NOVA LINCS, DI, FCT, Universidade NOVA de Lisboa, Portugal Marc Shapiro Sorbonne Universités, Inria, UPMC-LIP6, Paris, France ABSTRACT Client-side apps (e.g., mobile or in-browser) need cloud data to be available in a local cache, for both reads and up- dates. For optimal user experience and developer support, the cache should be consistent and fault-tolerant. In or- der to scale to high numbers of unreliable and resource-poor clients, and large database, the system needs to use resources sparingly. The SwiftCloud distributed object database is the first to provide fast reads and writes via a causally-consistent client-side local cache backed by the cloud. It is thrifty in resources and scales well, thanks to consistent versioning provided by the cloud, using small and bounded metadata. It remains available during faults, switching to a different data centre when the current one is not responsive, while maintaining its consistency guarantees. This paper presents the SwiftCloud algorithms, design, and experimental eval- uation. It shows that client-side apps enjoy the high per- formance and availability, under the same guarantees as a remote cloud data store, at a small cost. Categories and Subject Descriptors C.2.4 [Computer-Communication Networks]: Distributed Systems—distributed databases; H.3.4 [Information Storage and Retrieval]: Systems and Software—distributed systems General Terms Algorithms, Design, Performance, Reliability Keywords Geo-replication, Causal Consistency, Eventual Consistency, Fault Tolerance, Client-side Storage * Now at Google Inc. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. Middleware ’15 December 07-11, 2015, Vancouver, BC, Canada c 2015 ACM ISBN 978-1-4503-3618-5/15/12$15.00 DOI: http://dx.doi.org/10.1145/2814576.2814733. 1. INTRODUCTION Client-side applications, such as in-browser and mobile apps, are not well supported by current technology. Such apps need, not only to share data remotely, but also to cache and update data locally in order to remain responsive at all times. Existing cloud databases provide only remote data sharing. Developers may implement caching and buffering at the application level, but, in addition to adding complexity, this approach cannot provide system-wide consistency, ses- sion guarantees, or fault tolerance. Recent frameworks such as Google Drive Realtime API, TouchDevelop or Mobius [10, 12, 13] do cache data at the client side on a small scale, but do not ensure system-wide guarantees either. Even re- cent algorithms designed for geo-replication across data cen- tres [3, 5, 17, 25, 26] or small numbers of clients [8, 28] are not adequate for the task, as they are not designed to scale to large numbers of client-side replicas. We argue here for a distributed database design that in- cludes safety and scalability guarantees to client-side appli- cation developers. This system should address the (some- what conflicting) requirements of consistency, availability, and convergence [27], and uphold them at least as well as existing server-side systems. Since updates should be always available, concurrency is inevitable. However, no update should be lost, and the database replicas should never diverge permanently. Un- der these requirements, the strongest possible consistency model is convergent causal consistency with support for application-specific concurrency resolution [4, 25, 27, 33]. High numbers of client-side replicas challenges classi- cal approaches: (i) To track causality precisely, per client replica, creates unacceptably fat metadata; but the more compact server-side metadata management has fault- tolerance issues. (ii) Full replication at high numbers of resource-poor devices would be unacceptable [8]; but par- tial replication of data and metadata could cause anoma- lous message delivery or unavailability. (iii) Unlike many previous approaches [3, 17, 25, 26], fault tolerance and con- sistency cannot be solved by assuming that the application is located inside the data centre (DC), or has a sticky session to a single DC [6, 35]. We analyse the above challenges in more detail hereafter. This work addresses these challenges. We present the al- gorithms, design, and evaluation of SwiftCloud, the first dis- tributed object store designed for a high number of client-

Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

Write Fast, Read in the Past: Causal Consistency forClient-Side Applications

Marek ZawirskiSorbonne Universités, Inria,UPMC-LIP6, Paris, France∗

Nuno PreguiçaNOVA LINCS, DI, FCT,Universidade NOVA de

Lisboa, Portugal

Sérgio DuarteNOVA LINCS, DI, FCT,Universidade NOVA de

Lisboa, Portugal

Annette BieniusaU. of Kaiserslautern, Germany

Valter BalegasNOVA LINCS, DI, FCT,Universidade NOVA de

Lisboa, Portugal

Marc ShapiroSorbonne Universités, Inria,UPMC-LIP6, Paris, France

ABSTRACTClient-side apps (e.g., mobile or in-browser) need cloud datato be available in a local cache, for both reads and up-dates. For optimal user experience and developer support,the cache should be consistent and fault-tolerant. In or-der to scale to high numbers of unreliable and resource-poorclients, and large database, the system needs to use resourcessparingly. The SwiftCloud distributed object database is thefirst to provide fast reads and writes via a causally-consistentclient-side local cache backed by the cloud. It is thrifty inresources and scales well, thanks to consistent versioningprovided by the cloud, using small and bounded metadata.It remains available during faults, switching to a differentdata centre when the current one is not responsive, whilemaintaining its consistency guarantees. This paper presentsthe SwiftCloud algorithms, design, and experimental eval-uation. It shows that client-side apps enjoy the high per-formance and availability, under the same guarantees as aremote cloud data store, at a small cost.

Categories and Subject DescriptorsC.2.4 [Computer-Communication Networks]:Distributed Systems—distributed databases; H.3.4[Information Storage and Retrieval]: Systemsand Software—distributed systems

General TermsAlgorithms, Design, Performance, Reliability

KeywordsGeo-replication, Causal Consistency, Eventual Consistency,Fault Tolerance, Client-side Storage

∗Now at Google Inc.

Permission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copies are notmade or distributed for profit or commercial advantage and that copies bearthis notice and the full citation on the first page. Copyrights for componentsof this work owned by others than ACM must be honored. Abstracting withcredit is permitted. To copy otherwise, or republish, to post on servers or toredistribute to lists, requires prior specific permission and/or a fee. Requestpermissions from [email protected] ’15 December 07-11, 2015, Vancouver, BC, Canadac© 2015 ACM ISBN 978-1-4503-3618-5/15/12$15.00

DOI: http://dx.doi.org/10.1145/2814576.2814733.

1. INTRODUCTIONClient-side applications, such as in-browser and mobile

apps, are not well supported by current technology. Suchapps need, not only to share data remotely, but also to cacheand update data locally in order to remain responsive at alltimes. Existing cloud databases provide only remote datasharing. Developers may implement caching and buffering atthe application level, but, in addition to adding complexity,this approach cannot provide system-wide consistency, ses-sion guarantees, or fault tolerance. Recent frameworks suchas Google Drive Realtime API, TouchDevelop or Mobius[10, 12, 13] do cache data at the client side on a small scale,but do not ensure system-wide guarantees either. Even re-cent algorithms designed for geo-replication across data cen-tres [3, 5, 17, 25, 26] or small numbers of clients [8, 28] arenot adequate for the task, as they are not designed to scaleto large numbers of client-side replicas.

We argue here for a distributed database design that in-cludes safety and scalability guarantees to client-side appli-cation developers. This system should address the (some-what conflicting) requirements of consistency, availability,and convergence [27], and uphold them at least as well asexisting server-side systems.

Since updates should be always available, concurrency isinevitable. However, no update should be lost, and thedatabase replicas should never diverge permanently. Un-der these requirements, the strongest possible consistencymodel is convergent causal consistency with support forapplication-specific concurrency resolution [4, 25, 27, 33].

High numbers of client-side replicas challenges classi-cal approaches: (i) To track causality precisely, perclient replica, creates unacceptably fat metadata; but themore compact server-side metadata management has fault-tolerance issues. (ii) Full replication at high numbers ofresource-poor devices would be unacceptable [8]; but par-tial replication of data and metadata could cause anoma-lous message delivery or unavailability. (iii) Unlike manyprevious approaches [3, 17, 25, 26], fault tolerance and con-sistency cannot be solved by assuming that the applicationis located inside the data centre (DC), or has a sticky sessionto a single DC [6, 35]. We analyse the above challenges inmore detail hereafter.

This work addresses these challenges. We present the al-gorithms, design, and evaluation of SwiftCloud, the first dis-tributed object store designed for a high number of client-

Page 2: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

DC

DC

DC C

C

C

C

C

C

A P I

C C

C

A P I

A P I

App

App

App

geo-replication

Figure 1: System components (Application pro-cesses, Clients, Data Centres), and their interfaces.

side replicas. It efficiently ensures consistent, available, andconvergent access to client nodes, tolerating failures. To en-able both small metadata and fault tolerance, SwiftClouduses a flexible client-server topology, and decouples readsfrom writes. The client writes fast into its own cache, andreads in the past (also fast) data that is consistent, but oc-casionally stale.

Our main contribution is a combination of two tech-niques:

Cloud-backed support for partial replicas (§3).A DC serves a consistent view of the database to a client,

which the client merges with its own updates. In somefailure situations, a client may connect to a new DC thathappens to be inconsistent with its previous one. Becausethe client does not have a full replica, it cannot fix the is-sue on its own. We leverage “reading in the past” to avoidthis situation in the common case, and provide control overthe inherent trade-off between staleness and unavailability.More precisely, a client observes a remote update only if itis stored in some number K ≥ 1 of DCs [28]; the higher thevalue of K, the more likely that a K-stable version is in bothDCs, but the higher the staleness.

Protocols with decoupled, bounded metadata (§4).SwiftCloud features a decoupled metadata design [23] that

separates tracking causality, which uses small vectors as-signed in the background by DCs, from unique identifica-tion, based on client-assigned scalar timestamps. Thanksto this design, to the flexible client-server topology, and to“reading in the past,” metadata remains small and boundedin size. Furthermore, a DC can prune its log independentlyof clients, replacing it with a summary of delivered updates.

We implement SwiftCloud and demonstrate experimen-tally that our design reaches its objective, at a modest stale-ness cost. We evaluate SwiftCloud in Amazon EC2, againsta port of WaltSocial [34] and against YCSB [14]. Whendata is cached, response time is two orders of magnitudelower than for server-based protocols with similar availabil-ity guarantees. With three servers in different DCs, thesystem can scale to 2,500 of client replicas. Metadata sizedoes not depend on the number of clients, the number of fail-ures, or the size of the database, and increases only slightlywith the number of DCs: on average, 15 bytes of metadataper update, compared to kilobytes for previous algorithmswith similar safety guarantees. Throughput is comparable toserver-side replication, and improved for high locality work-loads. When a DC fails, its clients switch to a new DC inunder 1000 ms, and remain consistent. Under normal con-ditions, 2-stability causes fewer than 1% stale reads.

An extended version of this work is available as a technicalreport [36].

2. PROBLEM OVERVIEWWe consider support for a variety of client-side applica-

tions, sharing a database of objects that clients can readand update. We aim to scale to thousands of clients, span-ning the whole internet, and to a database of arbitrary size.

Fig. 1 illustrates our system model. A cloud infrastructureconnects a small set (say, tens) of geo-replicated data cen-tres, and a large set (thousands) of clients. A DC has abun-dant computational, storage and network resources. Simi-larly to Sovran et al. [34], we abstract a DC as a powerfulsequential process that hosts a full replica of the database.1

DCs communicate in a peer-to-peer way. A DC may fail andrecover with its persistent memory intact.

Clients do not communicate directly, but only via DCs.Normally, a client connects to a single DC; in case of fail-ure or roaming, to zero or more. A client may fail andrecover (e.g., disconnection while travelling) or fail perma-nently (e.g., destroyed phone), both without prior warning.We consider only non-byzantine failures.

Client-side apps need to respond quickly and at all times,i.e., they require high availability and responsiveness.This can be achieved by replicating data locally, and by syn-chronising updates in the background. However, a client haslimited resources; therefore, it hosts a cache that containsonly the small subset of the database of current interest tothe local app. It should not have to receive messages relativeto objects that it does not currently replicate [31]. Finally,control messages and piggy-backed metadata should havesmall and bounded size.

Since a client replica is only partial, there cannot be aguarantee of complete availability. The best that can be ex-pected is conditional availability, whereby an operationreturns without remote communication if the requested ob-ject is cached; and after retrieving the data from a remotenode (DC) if not. If the data is not there and the network isdown, the operation may be unavailable, i.e., it either blocksor returns an error.

2.1 Consistency with convergenceApplication programmers and users wish to observe a con-

sistent view of the global database. However, with avail-ability as a requirement, consistency options are limited[4, 19, 20, 27].

Causal consistency.The strongest available and convergent model is causal

consistency [2, 4, 27].Informally, under causal consistency, every process ob-

serves a monotonically non-decreasing set of updates that in-cludes its own updates, in an order that respects the causalitybetween operations.2 Specifically, if an application processreads x, and later reads y, and if the state of x causally-depends on some update u to y, then the state of y that itreads will include update u. When the application requestsy, we say there is a causal gap if the local replica has notyet received u. A consistent system must detect such a gap,

1We refer to prior work for the somewhat orthogonal issuesof parallelism and fault-tolerance within a DC [3, 17, 25, 26].2This subsumes the well-known session guarantees [11, 35].

Page 3: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

and wait until u is delivered before returning y, or avoidit in the first place. If not, inconsistent reads expose bothprogrammers and users to anomalies caused by gaps [25, 26].

We extend causal consistency with multi-operationcausal transactions. Such a transaction reads from acausally-consistent snapshot, and is atomic, i.e., eitherall its updates are visible, or none is [25, 26]. The transac-tion’s updates are considered to causally depend on all ofthe transaction’s reads.

Convergence.Applications require convergence, which consists of live-

ness and safety properties: (i) At-least-once delivery:an update that is delivered (i.e., is visible by the app) atsome node, is delivered to all interested nodes (i.e., nodesthat replicate or cache the updated object) after a finitenumber of message exchanges; (ii) Confluence: on twonodes that have delivered the same set of updates for anobject, the object has the same value.

Causal consistency does not guarantee confluence, as tworeplicas might receive the same updates in different orders.For confluence, we rely on CRDTs, high-level data typeswith rich confluent semantics [11, 33]. An update on a high-level object is not just an assignment, but is a method as-sociated with the object’s type. For instance, a Set objectsupports add(element) and remove(element); a Counter sup-ports increment() and decrement().

CRDTs include primitive last-writer-wins register (LWW)and multi-value register (MVR) [16, 21], but also higherlevel types such as Sets, Lists, Maps, Graphs, Counters, etc.[1, 32–34]. Efficient support of high-level objects requiresthe system to ensure both causal consistency (e.g., in a Setobject, to ensure that remove update is delivered after addsit depends on) and at-most-once delivery, since manyupdates are not idempotent (e.g., incrementing a Counter).

Although each of these requirements may seem familiar orsimple in isolation, the combination with scalability to highnumbers of nodes and database size is a new challenge.

2.2 Metadata designMetadata serves to identify updates and to ensure correct

delivery. Metadata is piggy-backed on update messages, in-creasing the cost of communication.

One common metadata design assigns each update atimestamp as soon as it is generated on some originatingnode. The causality data structures tend to grow “fat.” Forinstance, dependency lists [25] grow with the number of up-dates [17, 26], whereas version vectors [8, 28] grow withthe number of clients. (Indeed, our experiments hereaftershow that their size becomes unreasonable). We call thisthe Client-Assigned, Safe but Fat approach.

An alternative delegates timestamping to a small numberof DC servers [3, 17, 26]. This enables the use of small vec-tors, at the cost of losing some parallelism. However, this isnot fault tolerant if the client does not reside in a DC failuredomain. For instance, it may violate at-most-once delivery.Consider a client transmitting update u to be timestampedby DC 1. If it does not receive an acknowledgement, it re-tries, say with DC 2 (failover). This may result in u receivingtwo distinct timestamps, and being delivered twice. Du-plicate delivery violates safety for many confluent types, orotherwise complicates their implementation [11, 26]. We callthis the Server-Assigned, Lean but Unsafe approach.

Clearly, neither “fat” nor “unsafe” is satisfactory.

2.3 Causal consistency with partial replica-tion is hard

Since a partial replica receives only a subset of the up-dates, and hence of metadata, it could miss some causal de-pendencies [8]. Consider the following example: Alice postsa photo on her wall in a social network application (updatea). Bob sees the photo and mentions it in a message toCharles (update b), who in turn mentions it to David (up-date c). When David looks at Alice’s wall, he expects toobserve update a and view the photo. However, if David’smachine does not cache Charles’ inbox, it cannot observethe causal chain a → b → c and might incorrectly deliver cwithout a. Metadata design should protect from such causalgaps, caused by transitive dependency over absent objects.

Failures complicate the picture even more. Suppose Davidsees Alice’s photo, and posts a comment to Alice’s wall (up-date d). Now a failure occurs, and David’s machine failsover to a new DC. Unfortunately, the new DC has not yetreceived Bob’s update b, on which comment d causally de-pends. Therefore, it cannot deliver the comment, i.e., fulfillconvergence, without violating causal consistency. Davidcannot read new objects from the DC for the same reason.3

Finally, a DC logs an individual update for only a limitedamount of time, but clients may be unavailable for unlimitedperiods. Suppose that David’s comment d is accepted by theDC, but David’s machine disconnects before receiving theacknowledgement. Much later, after d has been executedand purged away, David’s machine comes back, only to retryd. This could violate at-most-once delivery; some previoussystems avoid this with fat version vectors [8, 28] or dependon client availability [23].

3. THE SWIFTCLOUD APPROACHWe now describe an abstract design that addresses the

above challenges, first in the failure-free case, and next, howwe support DC failure. Our design applies the principles ofconsistency algorithms for full replication systems to builda cloud-based support for partial client replicas.

3.1 Causal consistency at full DC replicasEnsuring causal consistency at fully-replicated DCs is a

well-known problem [2, 17, 25, 26]. Our design is log-based,i.e., SwiftCloud stores updates in a log and transmits themincrementally; it includes optimisations, where the full log isoccasionally replaced by the state of an object, called check-point [8, 29]. We discuss checkpoints only where relevant.

A database version is any subset of updates, noted U ,ordered by causality. A version maps object identifiers toobject state, by applying the relevant subsequence of thelog; the value of an object is exposed via the read API.

We say that a version U has a causal gap, or is incon-sistent if it is not causally-closed, i.e., if ∃u, u′ : u→ u′∧u 6∈U ∧ u′ ∈ U . As we illustrate shortly, reading from an incon-sistent version should be avoided, because, otherwise, subse-quent accesses might violate causality. On the other hand,waiting for the gap to be filled would increase latency anddecrease availability. To side-step this conundrum, we adopt

3Note that David can still perform updates, but they cannotbe delivered, thus the system does not converge.

Page 4: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

x.add(1) x.add(3)

V1 V2

y.add(2) y.add(1)

U1

(a) Initial configuration

x.add(1) x.add(3)

V1 V2

y.add(2) y.add(1)

x.add(4)

UC

read x {1,3}

(b) Continuation from 2(a) to risky configuration

x.add(1) x.add(3)

V1 V2

y.add(2) y.add(1)

x.add(4) read x

{1}

UC

(c) Read-in-the-past: cont. from 2(a) to conservativeconfiguration

Figure 2: Example evolution of configurations fortwo DCs, and a client. x and y are Sets; box = up-date; arrow = causal dependence (an optional text indicatesthe source of dependency); dashed box = named databaseversion/state.

the approach of “reading in the past” [2, 25]. Thus, a DCexposes a gapless but possibly delayed state, noted V .

To illustrate, consider the example of Fig. 2(a). Objectsx and y are of type Set. DC 1 is in state U1 that includesversion V1 ⊆ U1, and DC 2 in a later state V2. VersionsV1 with value [x 7→ {1}, y 7→ {1}] and V2 with value [x 7→{1, 3}, y 7→ {1, 2}] are both gapless. However, version U1,with value [x 7→ {1, 3}, y 7→ {1}] has a gap, missing updatey.add(2). When a client requests to read x at DC 1 in stateU1, the DC could return the most recent version, x : {1, 3}.However, if the application later requests y, to return a safevalue of y requires to wait for the missing update from DC 2.By “reading in the past” instead, the same replica exposesthe older but gapless version V1, reading x : {1}. Then, thesecond read will be satisfied immediately with y : {1}. Oncethe missing update is received from DC 2, DC 1 may advancefrom version V1 to V2.

A gapless algorithm maintains a causally-consistent,monotonically non-decreasing progression of replica states[2]. Given an update u, let us note u.deps its set of causalpredecessors, called its dependency set. If a full replica, insome consistent state V , receives u, and its dependencies aresatisfied, i.e., u.deps ⊆ V , then it applies u. The new state isV ′ = V ⊕{u}, where we note by ⊕ the log merge operatorthat unions the two logs, respecting causality (the operatorfilters out duplicates, as we discuss in §4.1). State V ′ isconsistent, and monotonicity is respected, since V ⊆ V ′.

If the dependencies are not met, as detected using meta-data, the replica buffers u until the causal gap is filled.

3.2 Causal consistency at partial client repli-cas

As a client replica contains only part of the database andits metadata, this complicates consistency [8]. To relieve

clients of this complexity, we move most of the burden ofmanaging gapless versions to the DC-side full replica.

At any point in time, a client is interested in a subset of theobjects in the database, called its interest set. Its initialstate consists of the projection of some DC’s state onto itsinterest set. This is a causally-consistent state, as shown inthe previous section. Client state can change, either becauseof an update generated by the client itself, called an inter-nal update, or because of one received from a DC, calledexternal. An internal update obviously maintains causalconsistency. If the same DC sends external updates with nogaps, then the client state remains causally consistent.

More formally, let i ∈ DC denote DC identifiers and m ∈C client identifiers with DC ∩ C = ∅. Where appropiate,we use simply DC and C to refer to some DC and client,respectively.

Consider some recent DC state, which we will call thebase version of the client, noted VDC . The interest set ofclient C is noted O ⊆ x, y, . . .. The client state, noted VC ,is restricted to these objects. It consists of two parts. Oneis the projection of base version VDC onto its interest set,noted VDC |O. The other is the log of internal updates, notedUC . The client state is their merge VC = VDC |O⊕UC |O. Oncache miss, the client adds the missing object to its interestset, and fetches the object from base version VDC , therebyextending the projection.

Base version VDC is a monotonically non-decreasing causalversion (it might be slightly behind the actual current stateof the DC due to propagation delays). By induction, in-ternal updates can causally depend only on internal up-dates, or on updates taken from the base version. There-fore, a hypothetical full version VDC ⊕UC would be causallyconsistent. Its projection is equivalent to the client state:(VDC ⊕ UC)|O = VDC |O ⊕ UC |O = VC .

This approach ensures conditional availability. Readsfrom a version in the cache are always available and guaran-teed causally consistent, although possibly slightly stale. If aread misses in the cache, the DC returns a consistent versionimmediately. Furthermore, the client replica can write fast,because it commits updates without waiting, and transfersthem to its DC in the background.

Convergence is ensured, because the client’s base versionand log are synchronised with the DC in the background.

3.3 Failover and causal dependenciesThe approach described so far assumes that a client con-

nects to a single DC. However, a client can switch to anew DC at any time, in particular in response to a failure.Although each DC’s state is consistent, an update that isdelivered to one is not necessarily delivered in the other (be-cause geo-replication is asynchronous, to ensure availabilityand performance at the DC level), which could potentiallycreate a causal gap in the client.

To illustrate the problem, return to the example ofFig. 2(a). Consider two DCs: DC 1 is in (consistent) stateV1, and DC 2 in (consistent) state V2; DC 1 does not includetwo recent updates of V2. Client C, connected to DC 2, repli-cates object x only; its state is V2|{x}. Suppose that the clientreads the Set x : {1, 3}, and performs update u = add(4),transitioning to the configuration shown in Fig. 2(b).

If this client now fails over to DC 1, and the two DCscannot communicate, the system is not live:(1) Reads are not available: DC 1 cannot satisfy a request

Page 5: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

for y, since the version read by the client is more recentthan the DC 1 version, V2 6⊆ V1.

(2) Updates cannot be delivered (divergence): DC 1 cannotdeliver u, due to a missing dependency: u.deps 6⊆ V1.

Therefore, DC 1 must reject the client (i.e., withhold its re-quests) to avoid creating the gap in state V1 ⊕ UC .

3.3.1 Conservative read: possibly stale, but safeSwiftCloud provides a solution to this problem. To avoid

such gaps that cannot be satisfied, the insight is to dependonly on K-stable updates that are likely to be present inthe failover DC, similarly to Mahajan et al. [28].

A version V is K-stable if every one of its updates is repli-cated in at least K DCs, i.e., |{i ∈ DC | V ⊆ Vi}| ≥ K,where K ≥ 1 is a threshold configured w.r.t. expected fail-ure model. To this effect, each DC i maintains a consistentK-stable version V Ki ⊆ Vi, which contains the updatesfor which DC i has received acknowledgements from at leastK − 1 distinct other DCs.

A client’s base version must be K-stable, i.e., VC =V KDC |O ⊕ UC |O, to support failover. In this way, the clientdepends, either on external updates that are likely to befound in any DC (V KDC ), or internal ones, which the clientcan always transfer to the new DC (UC).

To illustrate, let us return to Fig. 2(a), and consider theconservative progression to Fig. 2(c), assuming K = 2. Theclient’s read of x returns the 2-stable version {1}, avoidingthe dangerous dependency via an update on y. If DC 2 isunavailable, the client can fail over to DC 1, reading y andpropagating its update remain both live.

By the same arguments as in §3.2, a DC version V KDC iscausally consistent and monotonically non-decreasing, andhence the client’s version as well. Note that a client observesits internal updates immediately, even if not K-stable.

Parameter K can be adjusted dynamically without im-pacting correctness. Decreasing it has immediate effect. In-creasing K has effect only for future updates, to preservemontonicity.

3.3.2 DiscussionThe source of the above problem is an transitive causal de-

pendency on an update to the object that the client replicadoes not replicate (y.add(2) in our example). As this isan inherent issue, we conjecture a general impossibility re-sult, stating that genuine partial replication, causal consis-tency, conditional availability and timely at-least-once de-livery (convergence) are incompatible. Accordingly, the re-quirements must be relaxed.

Note that in many previous systems, this impossibilitytranslates to a trade-off between consistency and availabilityon the one hand, and performance on the other [15, 25, 34]By “reading in the past,” we displace this to a trade-off be-tween freshness and availability, controlled by adjusting K.A higher K increases availability, but updates take longer tobe delivered;4 in the limit, K = N ensures complete avail-ability, but no client can deliver a new update when someDC is unavailable. A lower K improves freshness, but in-creases the probability that a client will not be able to failover, and that it will block until its original DC recovers. Inthe limit, K = 1 is identical to the basic protocol from §3.2,and is similar to blocking session-guarantee protocols [35].

4The increased number of concurrent updates that thiscauses is not a big problem, thanks to confluent types.

K = 2 is a good compromise for deployments with three ormore DCs, as it covers common scenarios of a DC failure ordisconnection [15, 22]. Our experimental evaluation showsthat it incurs a negligible staleness.

Network partitions.Client failover between DCs is safe and generally live, ex-

cept when the original set of K DCs were partitioned awayfrom both other DCs and the client, shortly after they deliv-ered a version to the client. In this case, the client blocks. Toside-step this unavoidable possibility, we provide an unsafeAPI to read inconsistent data.

When a set of fewer than K DCs is partitioned from otherDCs, the clients that connect to them do not deliver theirmutual updates until the partition heals. To improve live-ness in this scenario, SwiftCloud supports two heuristics:(i) a partitioned DC announces its “isolated” status, au-tomatically recommending clients to use another DC, and(ii) clients who cannot reach another DC that satisfies theirdependencies can use the isolated DCs with K temporarilylowered, risking unavailability if another DC fails.

4. DETAILED DESIGNWe now describe a metadata and concrete protocols im-

plementing the abstract design.

4.1 MetadataThe SwiftCloud approach requires metadata: (1) to

uniquely identify an update; (2) to encode its causal depen-dencies; (3) to identify and compare versions; (4) and toidentify all the updates of a transaction. We now describea metadata design that fulfils the requirements and has alow cost. It combines the strengths of the two approachesoutlined in Section 2.3, and is both lean and safe.

A timestamp is a pair (j, k) ∈ (DC ∪ C) × N, where jidentifies the node that assigned the timestamp (either aDC or a client) and k is a sequence number. Similarly toLadin et al. [23], the metadata assigned to some update ucombines: (i) a single client-assigned timestamp u.tCthat uniquely identifies the update, and (ii) a set of zeroor more DC-assigned timestamps u.TDC . At the initialclient, it has only the client timestamp; after delivery to aDC, it receives a DC timestamp; in case of DC failover, it myhave several DC timestamps. Nodes can refer to an updatevia any of its timestamps in order to tolerate failures. Theupdates in a transaction all have the same timestamp(s), toensure all-or-nothing delivery [34].

We represent a version or a dependency as a versionvector. A vector is a partial map from node ID to in-teger timestamp. For instance, when u has dependencyVV = [DC 1 7→ 1,DC 2 7→ 2], this means that u causallydepends on {(DC 1, 1), (DC 2, 1), (DC 2, 2)}. A vector has atmost one client entry, and multiple DC entries; thus, its sizeis bounded by the number of DCs, limiting network over-head. In contrast to a dependence graph, a vector compactlyrepresents transitive dependencies and can be evaluated lo-cally by any node.

We note by T the function that maps a vector VV to thetimestamps it represents:

T (VV ) = {(j, k) ∈ dom(VV )× N | k ≤ VV (j)}

Function V maps vector VV and state U to a database ver-

Page 6: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

sion, i.e., the set of updates in U that match the vector:

V(VV , U) = {u ∈ U | (u.TDC ∪ {u.tC}) ∩ T (VV ) 6= ∅}

(V is defined for states U that cover all timestamps of VV )Note that, for V, an update can be identified by any of

its timestamps equivalently and that V is monotonic withgrowing state U .

The log merge operator U1 ⊕ U2 eliminates duplicatesbased on client timestamps: two updates u1 ∈ U1, u2 ∈ U2

are identical if u1.tC = u2.tC . The merge operator mergestheir DC timestamps into u ∈ U1 ⊕ U2, such that u.TDC =u1.TDC ∪ u2.TDC .

4.2 ProtocolsWe now describe the protocols of SwiftCloud by following

the lifetime of an update, and with reference to Fig. 1.

State.The state of a DC UDC consists of a set of object ver-

sions maintained in durable storage. Each version individ-ually respects per-object causality and atomicity of trans-actions. A DC also maintains a vector VVDC that rep-resents a recent database version that preserves atomicityand causal consistency across objects. This state is notedVDC = V(VVDC , UDC ).

In addition to its own updates UC (its commit log), a clientstores the state received from its DC, and the correspondingvector. The former is the DC’s base version, projected tothe client’s interest set O, VDC |O (§3.2). The latter is a copyof the DC’s vector VVDC that describes the base version.

Client-side execution.When an application starts a transaction τ at client C,

the client initialises it with an empty buffer of updatesτ.U ← ∅ and a snapshot vector of the current base ver-sion τ.depsVV ← VVDC ; the DC can update the client’sbase version concurrently with the transaction execution. Aread in transaction τ is answered from the version identifiedby the snapshot vector, merged with its internal updates,τ.V = V(τ.depsVV , VDC |O)⊕ UC |O ⊕ τ.U . If the requestedobject is not in the client’s interest set, x 6∈ O, the clientextends its interest set, and returns the value once the DCupdates the base version projection.

When the application issues internal update u, it is ap-pended to the transaction buffer τ.U ← τ.U ⊕ {u}, and in-cluded in any later read. To simplify the notation, in thissection a transaction consists of at most one update. Thiscan be easily extended to multiple updates, by assigning thesame timestamp to all the updates of the same transaction,ensuring the all-or-nothing property [34].

The transaction commits locally at the client and neverfails. If the transaction made an update u ∈ τ.U , the clientreplica commits it locally as follows: (1) Assign it clienttimestamp u.tC = (C, k), where k counts the number ofupdate transactions at the client; (2) assign it a depen-dency vector initialised with the transaction snapshot vec-tor u.depsVV = τ.depsVV ; (3) append it to the commit logof local updates on stable storage UC ← UC ⊕ {u}. Thisterminates the transaction; the client can start a new one,which will observe the above update.

Transfer protocol: Client to DC.The transfer protocol transmits committed updates from

a client to its current DC, in the background. It repeatedlypicks the first unacknowledged committed update u from thelog. If any of u’s internal dependencies has recently beenassigned a DC timestamp, it merges this timestamp intothe dependency vector. Then, the client sends a copy of uto its current DC. The client expects an acknowledgementfrom the DC, containing the timestamp(s) T that the DCassigned to update u. The client records the timestamps inthe original update record u.TDC ← T . In the failure-freecase, T is a singleton.

A transfer request may fail for three reasons:(a) Timeout: the DC is suspected unavailable; the client

connects to another DC (failover) and repeats the pro-tocol.

(b) The DC reports a missing internal dependency, i.e., ithas not received some previous update of the client, as aresult of a prior failover. The client recovers by markingas unacknowledged all internal updates starting from theoldest missing dependency, and restarting the transferprotocol from that point.

(c) The DC reports a missing external dependency ; this isalso an effect of failover. In this case, the client triesyet another DC. The approach from §3.3.1 avoids thisfailing repeatedly.

Upon receiving update u, the DC verifies if its dependen-cies are satisfied, i.e., if T (u.depsVV ) ⊆ T (VVDC ). (If thischeck fails, the DC accordingly reports error (b) or (c) tothe client.) If the DC has not received this update pre-viously (i.e., if its client timestamp is new), the DC per-forms the following steps: (1) Assign it a DC timestampu.TDC ← {(DC ,VVDC (DC ) + 1))}, (2) store it durablyUDC ← UDC ⊕ {u}, (3) incorporate its DC timestamp intoVVDC , in order to make the update visible in the DC versionVDC . These steps may be interleaved and/or batched withtransfer requests from different clients. Only Step 3 needsto be linearisable.

If the update has been received before, the DC looks upits previously-assigned DC timestamps. In both cases, theDC acknowledges the transfer to the client with the DCtimestamp(s).

Geo-replication protocol: DC to DC.When a DC accepts a fresh transaction in the transfer pro-

tocol, its updates become available to geo-replication, andthe accepting DC sends them to all other DCs using uniformreliable broadcast. A DC that receives a broadcast messagecontaining update u does the following: (1) If the depen-dencies of u are not met, i.e., if T (u.depsVV ) 6⊆ T (VVDC ),buffer it until they are; (2) incorporate u into durable stateUDC ← UDC ⊕ {u} (if u is not fresh, the duplicate-resilientlog merge safely unions all timestamps); and (3) incorpo-rate its DC timestamp(s) into the DC version vector VVDC .This last step makes it available to the notification protocol.The K-stable version V KDC is maintained similarly.

Notification protocol: DC to Client.A DC maintains a best-effort notification session, over a

FIFO channel, to each of its connected clients. The softstate of a session includes a copy of the client’s interest setO and the last known base version vector used by the client,VV ′DC . The DC accepts a new session only if its own state isconsistent with the base version provided by the client, i.e.,if T (VV ′DC ) ⊆ T (VVDC ). Otherwise, the client is redirected

Page 7: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

YCSB [14] SocialApp [34]Type of objects LWW Map Set, Counter, RegisterObject payload 10 × 100 bytes variable

Read txnsread fields read wall (80%)

(A: 50% / B: 95%) see friends (8%)

Update txnsupdate field message (5%)

(A: 50% / B:5%) post status (5%)add friend (2%)

Objects / txn 1 (non-txnal) 2–5Database size 50,000 objects 400,000 objects

Object popularity uniform / Zipfian uniformSession locality 40% (low) / 80% (high)

Table 1: Characteristics of applications/workloads.

to another DC, since the DC would cause a causal gap withthe client’s state (see §3.3.1).

The DC sends over each channel a causal stream of updatenotifications.5 Notifications are batched according to eithertime or to rate [8]. A notification packet consists of a newbase version vector VVDC , and a log of all the updates Uδto the objects of the interest set, between the client’s pre-vious base vector VV ′DC and the new one. Formally, Uδ ={u ∈ UDC |O | u.TDC ∩ (T (VVDC ) \ T (VV ′DC )) 6= ∅}. Theclient applies the newly-received updates to its local statedescribed by the old base version, VDC |O ← VDC |O⊕Uδ, andassumes the new vector VVDC . If any of received updatesis a duplicate, the log merge operator discards it safely.

When the client detects a broken channel, it reinitiatesthe session, possibly on a new DC.

The interest set can change dynamically. When an objectis evicted from the cache, the notifications are lazily unsub-scribed to save resources. When it is extended with objectx, the DC responds with the version of x that includes allupdates to x up to the base version vector. To avoid races,a notification includes a hash of the interest set, which theclient checks.

4.3 Object checkpoints and log pruningUpdate logs consume substantial storage and, to smaller

extent, network. To avoid unbounded growth, a pruningprotocol periodically replaces the prefix of a log by a check-point. In the common case, a checkpoint is more compactthan the corresponding log of updates; for instance, a logcontaining one thousand increments to a Counter object,each with its timestamps, can be replaced by a checkpointcontaining just the number 1000 paired with a version vec-tor.

4.3.1 Log pruning in the DCThe log at a DC provides (a) protection from dupli-

cate update delivery, as abstracted by the ⊕ operator, and(b) the capability to compute different versions, for appli-cation processes reading at different causal times. A logentry for update u may be replaced with a checkpoint onceits duplicates have been filtered out, and once u has beendelivered to all interested application processes.

Precise evaluation of this condition would require accessto the client replica states. In practice, we need to pruneaggressively, but without violating correctness. In order to

5Alternatively, the client can ask for invalidations instead,trading responsiveness for lower bandwidth utilization andhigher DC throughput.

reduce the risk of pruning a version not yet delivered toan interested application (which could force it to restartan ongoing transaction), we prune only a delayed versionVV ∆

DC , where ∆ is a real-time delay [25, 26].To avoid duplicates despite log pruning, we extend DC

metadata as follows. DC i maintains an at-most-onceguard Gi : C → N, which records the sequence numberof each client’s last pruned update. The guard is local toa DC. Whenever the DC receives a transfer request or ageo-replication message for update u with client timestamp(C, k) that is not in its log, it checks if Gi(C) ≥ k. If sothe update is a duplicate of a pruned update, which the DCignores, nonetheless incorporating all of u’s DC timestampsin its version vector; and, if it was a transfer request, the DCreplies with a vector VV i, which is an overapproximation ofthe (discarded) set of u’s DC timestamps.

The notification protocol also uses checkpoints. On aclient cache miss, instead of a complete log, the DC sendsan equivalent checkpoint of the object, together with theclient’s guard entry, so that the client can merge it with itslog safely.

4.3.2 Pruning the client’s logManaging the log at a client is simpler. A client logs

its own updates UC , which may include updates to objectsthat are currently outside of its interest set. This enablesthe client to read its own updates, and to propagate themlazily to a DC when connected and convenient. An update ucan be discarded as soon as it appears in the K-stable baseversion V KDC , i.e., when the client becomes dependent on thepresence of u at a DC.

5. EVALUATIONWe implement SwiftCloud and evaluate it experimentally,

in comparison to alternatives. We show that SwiftCloudprovides: (i) fast response, under 1 ms for both reads andwrites to cached objects (§5.3); (ii) while supporting thou-sands of clients, throughput that scales with the numberof DCs and small metadata, sized linear in the number ofDCs (§5.4); (iii) fault-tolerance w.r.t. client churn (§5.5) andDC outages (§5.6); and (iv) low staleness, under 1% of stalereads under common conditions (§5.7).

5.1 Implementation and applicationsSwiftCloud and its applications are implemented in Java.6

SwiftCloud uses an extendable library of log-based CRDTtypes [33], in-memory storage, Kryo for data marshalling,and a custom RPC implementation. A client cache has afixed size and uses an LRU eviction policy.

Our client API resembles both production object stores,such as Riak 2.0 or Redis [1, 30], and prototype causal trans-actional stores, such as COPS or Eiger [25, 26]:

begin transaction() read(object) : valuecommit transaction() update(object, method(args . . . ))

The actual API also includes caching options omitted here.Along the lines of previous studies of causally-consistent

systems [3, 5, 26, 34], we use two different benchmarks,YCSB and SocialApp, summarised in Tab. 1.

YCSB [14] serves as a kind of micro-benchmark, with sim-ple requirements, measuring baseline costs and specific sys-tem properties in isolation. It has a simple key-field-value

6 https://github.com/SyncFree/SwiftCloud

Page 8: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

object model, which we implement as a LWW Map type, us-ing a default payload of ten fields of 100 bytes each. YCSBissues single-object reads and writes. We use two of thestandard YCSB workloads: update-heavy Workload A, andread-dominated Workload B. The object access pattern canbe set to either uniform or Zipfian. YCSB does not rely ontransactional semantics or high-level data types.

SocialApp is a social network application modelled afterWaltSocial [34]. It employs high-level data types such asSets, for friends and posts, LWW Register for profile in-formation, Counter for counting profile visits, and objectreferences. SocialApp accesses multiple objects in a causaltransaction to ensure that operations such as reading a wallpage and profile information behave consistently. The So-cialApp workload is read-dominated, but visiting a wall ac-tually increments the wall visit counter. The user popularitydistribution is uniform.

In order to model the locality behaviour of a client, bothYCSB and SocialApp are augmented with a facility to con-trol access locality, mimicking social network access patterns[9]. Within a client session, a workload generator draws uni-formly from a pool of session-specific objects with either 40%(low locality) or 80% (high locality) probability. Objects notdrawn from this local pool are drawn from the global distri-bution (uniform or Zipfian) described above. The local poolcan fit in the client’s cache.

5.2 Experimental setupWe run three DCs in geographically distributed Ama-

zon EC2 availability zones (Europe, Virginia, and Oregon),and a pool of distributed clients. Round-Trip Times (RTTs)between nodes are as follows:

Oregon DC Virginia DC Europe DCnearby clients 60–80 ms 60–80 ms 60–80 msEurope DC 177 ms 80 msVirginia DC 60 ms

Each DC runs on a single m3.m EC2 instance, cheap virtualhardware, equivalent to a single core 64-bit 2.0 GHz IntelXeon processor (2 ECUs) with 3.75 GB of RAM, and Open-JDK7 on Linux 3.2. Objects are pruned at random intervalsbetween 60–120 s, to avoid bursts of pruning activity. We de-ploy 500–2,500 clients on a separate pool of 90 m3.m EC2instances. Clients load DCs uniformly and use the closestDC by default, with a client-DC RTT ranging in 60–80 ms.

For comparison, we provide three protocol modes:(i) SwiftCloud mode (default) with client cache replicas of256 objects, refreshed with notifications at a rate ≤1 s by de-fault; (ii) Safe But Fat metadata mode with cache, but withclient-assigned metadata only (modelled after PRACTI, orDepot without cryptography [8, 28]), (iii) server-side repli-cation mode without client caches; in this mode, an up-date incurs two RTTs to a DC, modelling the cost of asynchronous write to a quorum of servers to ensure fault-tolerance comparable to SwiftCloud.

5.3 Response time and throughputWe run several experiments to compare SwiftCloud’s

client-side caching, with reference to the locality potentialand server-side geo-replication without caching.

Fig. 3 shows response times for YCSB, comparing server-only (left side) with client replication (right side), under low(top) and high locality (bottom), when the system is notoverloaded. Recall that in server-only replication, a read in-curs a RTT to the DC, whereas an update incurs 2 RTTs.

Server replicas only SwiftCloud w/client replicas

0 RT

T

1 RT

T

2 RT

T

locality potential

locality potential

0 RT

T

1 RT

T

0%25%50%75%

100%

0%25%50%75%

100%

Low locality

High locality

0 50 100 150 200 250 0 50 100 150 200 250operation response time [ms]

CD

F fo

r all

sess

ions

readupdate

Figure 3: Response time for YCSB operations(workload A, Zipfian object popularity) under dif-ferent system and workload locality configurations,aggregated for all clients.

YCSB A (50% updates) YCSB B (5% updates)

1

10

100

1000

1

10

100

1000

Zipfian distrib.uniform

distrib.

1250 2500 5000 5000 10000 20000throughput [txn/s]

resp

onse

tim

e [m

s]

server replicas only, 70th percentile of response time (exp. local)client replicas, 70th percentile of response time (exp. local)server replicas only, 95th percentile of respone time (remote)client replicas, 95th percentile of respone time (remote)

Figure 4: Throughput vs. response time for differ-ent system configurations running variants of YCSB.

We expect SwiftCloud to provide much faster response, atleast for cached data. Indeed, the figure shows that a sig-nificant fraction of operations respond immediately in Swift-Cloud mode, and this fraction tracks the locality of the work-load (marked “locality potential” on the figure), within a±7.5 percentage-point margin attributable to caching policyartefacts. The remaining operations require one round-tripto the DC, indicated as 1 RTT. As our measurements forSocialApp show the same message, we do not report themhere. These results demonstrate that the consistency guar-antees and the rich programming interface of SwiftCloud donot affect responsiveness of read and update of cached data.

In terms of throughput, client-side replication is a mixedblessing: it lets client replicas absorb read requests thatwould otherwise reach the DC, but also puts extra load ofmaintaining client replicas on DCs. In another experiment(not plotted), we saturate the system to determine its max-imum throughput. SwiftCloud’s client-side replication con-sistently improves throughput for high-locality workloads,by 7% up to 128%. It is especially beneficial to read-heavyworkloads. In contrast, low-locality workloads show no cleartrend; depending on the workload, throughput either in-creases by up to 38%, or decrease by up to 11%.

Our next experiment studies how response times vary with

Page 9: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

●●

● ●

● ● ●●

● ● ● ● ●● ● ● ● ●/ limit

● ●

●●

●●

●●

● ●●

/ limit

● ● ●● ●

● ● ● ● ●

● ●● ● ●●

● ● ● ●

YCSB A, uniform YCSB B, uniform SocialApp

0

5000

10000

15000

20000

25000

500 1500 2500 500 1500 2500 500 1500 2500#client replicas

max

. thr

ough

put [

txn/

s] ●●

●●

refresh rate 1srefresh rate 10s

3 DC replicas1 DC replica

Figure 5: Maximum system throughput for a vari-able number of client and DC replicas.

server load and with the staleness settings. The results showthat, as expected, cached objects respond immediately andare always available, but the responsiveness of cache missesdepends on server load. For this study, Fig. 4 plots through-put vs. response time, for YCSB A (left side) and B (rightside), both for the Zipfian (top) and uniform (bottom) distri-butions. Each point represents the aggregated throughputand latency for a given transaction incoming rate, whichwe increase until reaching the saturation point. The curvesreport two percentiles of response time: the lower (70th per-centile) line represents the response time for requests thathit in the cache (the session locality level is 80%), whereasthe higher (95th percentile) line represents misses, i.e., re-quests served by a DC.

As expected, the lower (cached) percentile consistentlyoutperforms the server-side baseline, for all workloads andtransaction rates. A separate analysis, not reported in detailhere, reveals that a saturated DC slows down its rate ofnotifications, increasing staleness, but this does not impactresponse time, as desired. In contrast, the higher percentilefollows the trend of server-side replication response time,increasing remote access time.

Varying the target notification rate (not plotted) between500 ms and 1000 ms, reveals the same trend: response timeis not affected by the increased staleness. At a lower refreshrate, notification batches are less frequent but larger. Thisincreases throughput for the update-heavy YCSB A (up totens of percent points), but has no effect on the throughputof read-heavy YCSB B. We expect the impact of refresh rateto be amplified for workloads with smaller rate of notifica-tion updates.

5.4 ScalabilityNext, we measure how well SwiftCloud scales with increas-

ing numbers of DC and of client replicas. Of course, per-formance is expected to increase with more DCs, but mostimportantly, the size of metadata should be small, shouldnot depend on the number of clients, and should increaselinearly with the number of DCs. Our results confirm theseexpectations.

In this experiment, we run SwiftCloud with a variablenumber of client (500–2500) and server (1–3) replicas. Wereport only on the uniform object distribution, because, un-der zipfian distribution, it is challenging to maintain a con-stant total workload while varying the number of clients.To control staleness, we run SwiftCloud with two differentnotification rates (every 1 s and every 10 s).

YCSB A, uniform YCSB B, uniform SocialApp w/stats

max. notification data max. notification data max. notification data

10

100

1K

10K

100K

500 1500 2500500 1500 2500500 1500 2500#client replicas

notif

icat

ion

met

adat

a [B

]

1 DC replica3 DC replicas

SwiftCloud metadataSafe But Fat metadata (Depot*)

Figure 6: Size of metadata in notification messagefor a variable number of replicas, mean and standarderror. Normalised to a notification of 10 updates.

Fig. 5 shows the maximum system throughput on theY axis, increasing the number of replicas along the X axis.The thin lines are for a single DC, the bold ones for threeDCs. Solid lines represent the fast notification rate, dashedlines the slow one. The figure shows, left to right, YCSBWorkload A, YCSB Workload B, and SocialApp.

The capacity of a single DC in our hardware configurationpeaks at 2,000 active client replicas for YCSB, and 2,500 forSocialApp. Beyond that, the DC drops sessions.

As to be expected, additional DC replicas increase thesystem capacity for operations that can be performed at onlyone replica such as read operations or sending notificationmessages. Whereas a single SwiftCloud DC supports at most2,000 clients. With three DCs SwiftCloud supports at least2,500 clients for all workloads. Unfortunately, as we ranout of resources for client machines at this point, we cannotreport an upper bound.

For some fixed number of DCs, adding client replicasincreases the aggregated system throughput, until a pointwhere the cost of maintaining client replicas up to date sat-urates the DCs, and further clients do not absorb enoughreads to overcome that cost. Note that the lower refresh ratecan control the load at a DC, and reduces it by 5 to 15%.

In the same experiment, Fig. 6 presents the distributionof metadata size in notification messages. (Notifications arethe most common and the most costly messages sent overthe network.) We plot the size of metadata (in bytes) onthe Y axis, varying the number of clients along the X axis.Left to right, the same workloads as in the previous figure.Thin lines are for one DC, thick lines for three DCs. A solidline represents SwiftCloud “Lean and Safe” metadata, anddotted lines the classical “Safe But Fat”approach. Note thatour Safe-but-Fat implementation includes the optimisationof sending modified entries of vector rather than the full vec-tor, as in Depot or PRACTI [8, 28]. Vertical bars representstandard error across clients. As notifications are batched,we normalise metadata size to a message carrying exactly10 updates, corresponding to under approx. 1 KB of data.

This plot confirms that the SwiftCloud metadata is smalland constant, at 100–150 bytes/notification (10–15 bytes perupdate); data plus metadata together fit inside a single stan-dard network packet. It is independent both from the num-ber of client replicas and from the workload. Increasing thenumber of DC replicas from one to three causes a negligibleincrease in metadata size, of under 10 bytes.

Page 10: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

YCSB − all objects SocialApp − stats counters● ● ● ● ● ● ● ● ● ●

● ● ● ● ● ● ● ● ● ●

1K

10K

100K

1M

10M

100M

0 1000 2000 3000 4000 0 1000 2000 3000 4000#unavailable client replicas

stor

age

occu

p. [B

]

SwiftCloud(SwiftCloud's at−most−once guard only)Lean But Unsafe approach w/o at−most−once guarantees

Figure 7: Storage occupation at one DC in reactionto client churn, for SwiftCloud and Lean-but-Unsafealternative.

In contrast, the classical Safe-but-Fat metadata grows lin-early with the number of clients and exhibits higher vari-ability. Its size reaches approx. 1 KB for 1,000 clients in allworkloads, and 10 KB for 2,500 clients. Clearly, metadatathat is up to 10× larger than the actual data represents asubstantial overhead.

5.5 Tolerating client churnWe now turn to fault tolerance. In the next experiment,

we evaluate SwiftCloud under client churn, by periodicallydisconnecting client replicas and replacing them with a newset of clients. At any point in time, there are 500 activeclients and a variable number of disconnected clients, up to5000. Fig. 7 illustrates the storage occupation of a DC forrepresentative workloads, which is also a proxy for the sizeof object checkpoints transferred. We compare SwiftCloud’slog compaction to a protocol without at-most-once deliveryguarantees (Lean But Unsafe).

SwiftCloud storage size is approximately constant thanksto the aggressive log compaction. This is safe thanks to theat-most-once guard table per DC. Although the size of theguard (bottom curve) grows with the number of clients, itrequires orders of magnitude less storage than the actualdatabase itself.

A protocol without at-most-once delivery guarantees usesLean-but-Unsafe metadata, without SwiftCloud’s at-most-once guard. This requires more complexity in each object’simplementation, to protect itself from duplicates. This in-creases the size of objects, impacting both storage and net-work costs. As is visible in the figure, the cost dependson the object type: none for YCSB’s LWW-Map, which isnaturally idempotent, vs. linear in the number of clients forSocialApp’s Counter objects.

We conclude that the cost of maintaining SwiftCloud’sat-most-once guard is negligible, and easily amortised by itsstable behaviour and possible savings.

5.6 Tolerating DC failuresThe next experiment studies the behaviour of SwiftCloud

when a DC disconnects. The scatterplot in Fig. 8 shows theresponse time of a SocialApp client application as the clientswitches between DCs. Starting with a cold cache, responsetimes quickly drops to near zero for transactions hitting inthe cache, and to around 110 ms for misses. Some 33 s intothe experiment, the current DC disconnects, and the clientis diverted to another DC in a different continent. Thanksto K-stability the failover succeeds, and the client continueswith the new DC. Response time for cache misses reflects

0 50

100 150 200 250 300 350 400

0 10 20 30 40 50 60 70 80resp

onse

tim

e [m

s]

time [s]

/ transient DC failure /

Figure 8: Response time for a client that hands overbetween DCs during a 30 s failure of a DC.

the higher RTT to the new DC. At 64 s, the client switchesback the initial DC, and performance smoothly recovers.

Recall that a server-side geo-replication system with sim-ilar fault-tolerance incurs high response time (cf. §5.3, orReference 15) and does not ensure at-most-once delivery.

5.7 Staleness costThe price to pay for our read-in-the-past approach is an

increase in staleness. We consider a read stale if there exists,at the client’s current DC, a non-K-stable version that ismore recent than the one returned. A transaction is staleif any of its reads is stale. In the experiments so far, weobserved a negligible number of stale reads and transactions,below 1 %. In another experiment (not plotted here), weartificially increase the probability of staleness by variousmeans, e.g., using a smaller database, and setting cache sizeto zero. Even in this case, stale reads and stale transactionsremain under 1% and 2.5% respectively.

6. RELATED WORK

6.1 Related results on consistency and avail-ability

Mahajan et al. [27] and Attiya et al. [4] prove that nostronger consistency model than causal consistency is avail-able and convergent, under full replication. We conjecturethat these properties are not simultaneously achievable un-der partial replication, and we show how to weaken one ofthe liveness properties. Bailis et al. [6] also study variantsof weak consistency models, and formulate a similar impos-sibility for a client switching server replicas. However, theydo not take into account the capabilities of a client replica,as we do.

Some operations or objects of application may requirestronger consistency, which requires synchronous protocols[20]. Prior work demonstrates that combining strong andweak consistency is possible [24, 34]. In particular, Balegaset al. [7] implemented protocols that enforce strong consis-tency invariants as a middleware layer on top of SwiftCloud.

6.2 Comparison with other systemsSeveral systems support consistent, available and conver-

gent data access, at different scales.

6.2.1 Replicated databases for client-side appsPRACTI [8] is a seminal work on causal consistency un-

der partial replication. PRACTI uses Safe-but-Fat client-assigned metadata and a flexible log-exchange protocol thatsupports arbitrary communication topologies and modes.While PRACTI is very general, it is not viable for large-scale

Page 11: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

client-side replication deployment: (i) Its fat metadata ap-proach (version vectors sized as the number of clients) isprohibitively expensive (see Fig. 6), and (ii) any replica canmake another unavailable, because of the transitive depen-dence issue discussed in §3.3.2.

Our high availability techniques are similar to Depot [28],a causally-consistent storage for the client-side, built on topof untrusted cloud replicas. Depot tolerates Byzantine cloudbehaviour using cryptographic metadata signatures, in orderto detect misbehaviour, and fat metadata, in order to sup-port direct client-to-client communication. Conservatively,Depot either exposes updates signed by K different serversor forces clients to receive all transitive dependencies of theirreads. This is at odds with genuine partial replication [31].Under no failures, a client receives metadata of every up-date; under failures, it may also receive their body. In con-trast, SwiftCloud relies on DCs to compute K-stable con-sistent versions with lean metadata. In the event of an ex-tensive failure involving K DCs, SwiftCloud provides theflexibility to decrease K dynamically or to weaken consis-tency.

Both PRACTI and Depot systems use Safe-but-Fatmetadata. They support only LWW registers, but theirrich metadata could conceivably accommodate high-levelCRDTs too.

Lazy Replication (LR) protocols [23] support multipleconsistency modes for client-side apps executing operationson server replicas. Under causal consistency, LR provideshigh availability with asynchronous read and write requeststo multiple servers. As suggested by Ladin et al. [23], LRcould also read stable updates for availability on failover,but that would force its clients to execute updates syn-chronously. The implementation of LR uses safe and leanmetadata similar to SwiftCloud, involving client- and server-assigned timestamps together with vector summaries. A logcompaction protocol relies on availability of client replicasand loosely-synchronised clocks for progress.

SwiftCloud structures the database into smaller CRDTobjects, which allows it to provide partial client replicas,whereas LR considers only global operations. We show thatclient replicas can offer higher responsiveness on cached ob-jects, instead of directing all operations to the server sideas in LR, and that local updates can be combined with K-stable updates into a consistent view, avoiding slow and un-available synchronous updates of LR. The log compactiontechnique of LR is complementary to ours, and optimisesfor the average case. SwiftCloud’s aggressive pruning relieson at-most-once guard table, optimising for failure scenarios.

Recent web and mobile application frameworks, such asTouchDevelop [10], Google Drive Realtime API [12], or Mo-bius [13] support replication for in-browser or mobile appli-cations. These systems are designed for small objects [12],database that fits on a mobile device [10], or a database ofindependent objects [13]. It is unknown if/how they sup-port multiple DCs and fault tolerance, whereas SwiftCloudsupports consistency, a large database, and fault tolerance.TouchDevelop provides a form of object composition, andoffers integration with strong consistency [10]. We are look-ing into ways of adapting similar mechanisms.

6.2.2 Server-side geo-replicated databasesA number of geo-replicated systems offer available

causally consistent data access inside a DC with excellent

scale-out by sharding [3, 5, 17, 18, 25, 26].Server-side geo-replication systems use variety of types of

metadata, mostly Lean-but-Unsafe metadata. COPS [25]assigns metadata directly at database clients, and uses ex-plicit dependencies (a graph). Follow-up work shows thatthis approach is costly, and assigns metadata at object/shard replicas instead [17, 26], or on a designated node inthe DC [3, 34]. The location of assignment directly impactsthe size of causality metadata. In most systems, it varieswith the number of reads, with the number of dependen-cies, and with the stability conditions in the system. Whenfewer nodes assign metadata, it tends to be smaller (as inSwiftCloud), but this may limit throughput. Recent workof Du et al. [18] make use of full stability, a special case ofK-stability, to remove the need for dependency metadata inmessages, thereby improving throughput.

Server-side designs do not easily extend beyond the scopeand the failure domain of a DC, because (i) their proto-cols do not tolerate external client failures and DC outages,either blocking or violating safety (due to inadequate meta-data, and the causal dependence issue); (ii) as they assumethat data is updated by overwriting, implementing high-levelconfluent data types that work on the client-side is complexand costly (see Fig. 7); (iii) their metadata can grow withdatabase size.

SwiftCloud’s support for server-side sharding is limitedcompared to the most scalable geo-replicated designs. Rec-onciling client-side replication with a more decentralisedsharding support, and small metadata size, is future work.

7. CONCLUSIONWe presented the design of SwiftCloud, the first object

database that offers client-side apps a local access to partialreplica with the guarantees of geo-replicated systems.

Our experiments show that the design of SwiftCloud isable to provide immediate and consistent response for readsand updates on local objects, and to maintain the through-put of a server-side geo-replication, or better. SwiftCloud’smetadata allows it to scale safely to thousands of clientswith 3 DCs, with small size objects, and metadata at thelevel of 15 bytes per update, independent of the number ofconnected and disconnected clients. Our fault-tolerant pro-tocols handle failures nearly transparently, at a low stalenesscost.

SwiftCloud’s design leverages a common principle thathelps to achieve several goals: client buffering and controlledstaleness can absorb the cost of scalability, availability, andconsistency.

Acknowledgments.Thanks to Carlos Baquero, Peter Bailis, Allen Clement,

Alexey Gotsman, Masoud Saeida Ardekani, Joao Leitao,Vivien Quema, Luıs Rodrigues, and the anonymous re-viewers, for their constructive comments. This researchis supported in part by ANR (France) project Con-coRDanT (ANR-10-BLAN 0208), by the Google Eu-rope Fellowship 2010 awarded to Marek Zawirski, by aGoogle Faculty Research Award 2013, by European FP7project SyncFree (609 551, 2013–2016), and by NOVALINCS (FCT UID/CEC/04516/2013, Portugal).

Page 12: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

References[1] Introducing Riak 2.0: Data types, strong consistency,

full-text search, and much more, Oct. 2013. URL http://basho.com/introducing-riak-2-0/.

[2] M. Ahamad, G. Neiger, J. E. Burns, P. Kohli, and P. W.Hutto. Causal memory: definitions, implementation,and programming. Distributed Computing, 9(1):37–49,Mar. 1995.

[3] S. Almeida, J. Leitao, and L. Rodrigues. ChainReac-tion: a causal+ consistent datastore based on ChainReplication. In Euro. Conf. on Comp. Sys. (EuroSys),Apr. 2013.

[4] H. Attiya, F. Ellen, and A. Morrison. Limitations ofhighly-available eventually-consistent data stores. InSymp. on Principles of Dist. Comp. (PODC), pages385–394. ACM, 2015.

[5] P. Bailis, A. Ghodsi, J. M. Hellerstein, and I. Stoica.Bolt-on causal consistency. In Int. Conf. on the Mgt. ofData (SIGMOD), pages 761–772, New York, NY, USA,2013.

[6] P. Bailis, A. Davidson, A. Fekete, A. Ghodsi, J. M.Hellerstein, and I. Stoica. Highly Available Transac-tions: Virtues and limitations. In Int. Conf. on VeryLarge Data Bases (VLDB), Riva del Garda, Trento,Italy, 2014.

[7] V. Balegas, N. Preguica, R. Rodrigues, S. Duarte,C. Ferreira, M. Najafzadeh, and M. Shapiro. Puttingthe consistency back into eventual consistency. In Euro.Conf. on Comp. Sys. (EuroSys), Bordeaux, France,Apr. 2015.

[8] N. Belaramani, M. Dahlin, L. Gao, A. Nayate,A. Venkataramani, P. Yalagandula, and J. Zheng.PRACTI replication. In Networked Sys. Design and Im-plem. (NSDI), pages 59–72, San Jose, CA, USA, May2006. Usenix.

[9] F. Benevenuto, T. Rodrigues, M. Cha, and V. Almeida.Characterizing user behavior in online social networks.In Internet Measurement Conference (IMC), 2009.

[10] S. Burckhardt. Bringing TouchDevelop to the cloud.Inside Microsoft Research Blog, Oct. 2013. URLhttp://blogs.technet.com/b/inside microsoft research/archive/2013/10/28/bringing-touchdevelop-to-the-cloud.aspx.

[11] S. Burckhardt, A. Gotsman, H. Yang, and M. Zawirski.Replicated data types: Specification, verification, opti-mality. In Symp. on Principles of Prog. Lang. (POPL),pages 271–284, San Diego, CA, USA, Jan. 2014.

[12] B. Cairns. Build collaborative apps with Google DriveRealtime API. Google Apps Developers Blog, Mar.2013. URL http://googleappsdeveloper.blogspot.com/2013/03/build-collaborative-apps-with-google.html.

[13] B.-G. Chun, C. Curino, R. Sears, A. Shraer, S. Mad-den, and R. Ramakrishnan. Mobius: Unified messagingand data serving for mobile apps. In Int. Conf. on Mo-bile Sys., Apps. and Services (MobiSys), pages 141–154,New York, NY, USA, 2012.

[14] B. F. Cooper, A. Silberstein, E. Tam, R. Ramakrishnan,and R. Sears. Benchmarking cloud serving systems withYCSB. In Symp. on Cloud Computing, pages 143–154,Indianapolis, IN, USA, 2010.

[15] J. C. Corbett, J. Dean, M. Epstein, A. Fikes, C. Frost,J. Furman, S. Ghemawat, A. Gubarev, C. Heiser,P. Hochschild, W. Hsieh, S. Kanthak, E. Kogan, H. Li,A. Lloyd, S. Melnik, D. Mwaura, D. Nagle, S. Quin-lan, R. Rao, L. Rolig, Y. Saito, M. Szymaniak, C. Tay-lor, R. Wang, and D. Woodford. Spanner: Google’sglobally-distributed database. In Symp. on Op. Sys.Design and Implementation (OSDI), pages 251–264,Hollywood, CA, USA, Oct. 2012. Usenix.

[16] G. DeCandia, D. Hastorun, M. Jampani, G. Kakula-pati, A. Lakshman, A. Pilchin, S. Sivasubramanian,P. Vosshall, and W. Vogels. Dynamo: Amazon’s highlyavailable key-value store. In Symp. on Op. Sys. Prin-ciples (SOSP), volume 41 of Operating Systems Re-view, pages 205–220, Stevenson, Washington, USA,Oct. 2007. Assoc. for Computing Machinery.

[17] J. Du, S. Elnikety, A. Roy, and W. Zwaenepoel. Orbe:Scalable causal consistency using dependency matricesand physical clocks. In Symp. on Cloud Computing,pages 11:1–11:14, Santa Clara, CA, USA, Oct. 2013.Assoc. for Computing Machinery.

[18] J. Du, C. Iorgulescu, A. Roy, and W. Zwaenepoel. Gen-tleRain: Cheap and scalable causal consistency withphysical clocks. In Symp. on Cloud Computing, 2014.

[19] R. Friedman and K. Birman. Trading consistencyfor availability in distributed systems. Technical Re-port TR96-1579, Cornell U., Computer Sc., Ithaca NY,USA, Apr. 1996.

[20] S. Gilbert and N. Lynch. Brewer’s conjecture andthe feasibility of consistent, available, partition-tolerantweb services. SIGACT News, 33(2):51–59, 2002.

[21] P. R. Johnson and R. H. Thomas. The maintenanceof duplicate databases. Internet Request for CommentsRFC 677, Information Sciences Institute, Jan. 1976.

[22] A. Kansal, B. Urgaonkar, and S. Govindan. Using darkfiber to displace diesel generators. In Hot Topics inOperating Systems, Santa Ana Pueblo, NM, USA, 2013.

[23] R. Ladin, B. Liskov, and L. Shrira. Lazy replication:Exploiting the semantics of distributed services. Oper-ating Systems Review, 25(1):49–55, Jan. 1991.

[24] C. Li, D. Porto, A. Clement, J. Gehrke, N. Preguica,and R. Rodrigues. Making geo-replicated systems fastas possible, consistent when necessary. In Symp. on Op.Sys. Design and Implementation (OSDI), pages 265–278, Hollywood, CA, USA, Oct. 2012.

[25] W. Lloyd, M. J. Freedman, M. Kaminsky, and D. G.Andersen. Don’t settle for eventual: scalable causalconsistency for wide-area storage with COPS. In Symp.on Op. Sys. Principles (SOSP), pages 401–416, Cascais,Portugal, Oct. 2011. Assoc. for Computing Machinery.

Page 13: Write Fast, Read in the Past: Causal Consistency for …...Write Fast, Read in the Past: Causal Consistency for Client-Side Applications Marek Zawirski Sorbonne Universités, Inria,

[26] W. Lloyd, M. J. Freedman, M. Kaminsky, and D. G.Andersen. Stronger semantics for low-latency geo-replicated storage. In Networked Sys. Design and Im-plem. (NSDI), pages 313–328, Lombard, IL, USA, Apr.2013.

[27] P. Mahajan, L. Alvisi, and M. Dahlin. Consistency,availability, and convergence. Technical Report UTCSTR-11-22, Dept. of Comp. Sc., The U. of Texas atAustin, Austin, TX, USA, 2011.

[28] P. Mahajan, S. Setty, S. Lee, A. Clement, L. Alvisi,M. Dahlin, and M. Walfish. Depot: Cloud storage withminimal trust. Trans. on Computer Systems, 29(4):12:1–12:38, Dec. 2011.

[29] K. Petersen, M. J. Spreitzer, D. B. Terry, M. M.Theimer, and A. J. Demers. Flexible update propaga-tion for weakly consistent replication. In Symp. on Op.Sys. Principles (SOSP), pages 288–301, Saint Malo,Oct. 1997. ACM SIGOPS.

[30] Redis. An open source key-value store. http://redis.io/,May 2014.

[31] N. Schiper, P. Sutra, and F. Pedone. P-Store: Genuinepartial replication in wide area networks. In Symp. onReliable Dist. Sys. (SRDS), pages 214–224, New Dehli,India, Oct. 2010. IEEE Comp. Society.

[32] M. Shapiro, N. Preguica, C. Baquero, and M. Zawirski.A comprehensive study of Convergent and Commuta-tive Replicated Data Types. Rapp. de Recherche 7506,Institut National de la Recherche en Informatique etAutomatique (Inria), Rocquencourt, France, Jan. 2011.

[33] M. Shapiro, N. Preguica, C. Baquero, and M. Zawirski.Conflict-free replicated data types. In X. Defago, F. Pe-tit, and V. Villain, editors, Int. Symp. on Stabilization,Safety, and Security of Distributed Systems (SSS), vol-ume 6976 of Lecture Notes in Comp. Sc., pages 386–400,Grenoble, France, Oct. 2011. Springer-Verlag.

[34] Y. Sovran, R. Power, M. K. Aguilera, and J. Li. Trans-actional storage for geo-replicated systems. In Symp.on Op. Sys. Principles (SOSP), pages 385–400, Cascais,Portugal, Oct. 2011. Assoc. for Computing Machinery.

[35] D. B. Terry, A. J. Demers, K. Petersen, M. J. Spre-itzer, M. M. Theimer, and B. B. Welch. Session guaran-tees for weakly consistent replicated data. In Int. Conf.on Para. and Dist. Info. Sys. (PDIS), pages 140–149,Austin, Texas, USA, Sept. 1994.

[36] M. Zawirski, N. Preguica, S. Duarte, A. Bieniusa,V. Balegas, and M. Shapiro. Write fast, read in thepast: Causal consistency for client-side applications.Rapp. de Recherche RR-8729, Institut National dela Recherche en Informatique et Automatique (Inria),Rocquencourt, France, May 2015.