33:toclevels: 3
44
55[[couchbase-mobile-2.0-replication-protocol]]
6- Couchbase Mobile 2.0 Replication Protocol
7- -----------------------------------------
6+ Couchbase Mobile Replication Protocol
7+ -------------------------------------
88
99Contributors: Jens Alfke, Traun Leyden, Ben Brooks, Jim Borden
1010
@@ -13,30 +13,6 @@ Protocol version 3
1313This document specifies the replication protocol in use by Couchbase Mobile
14142.0 and later. It supersedes the REST-based protocol inherited from CouchDB.
1515
16- Benefits of the new protocol are:
17-
18- * Faster and uses less bandwidth
19- * Consumes fewer TCP ports on the server (a limited resource)
20- * Opens a single TCP connection on the client instead of 4+ -- this
21- prevents problems with the limited number of sockets the client HTTP
22- library will open, which has led to deadlocks and performance problems
23- * Cleaner error handling, because socket-level connectivity errors only
24- happen on one socket instead of intermittently affecting some fraction
25- of requests
26- * Fully IANA compliant sparkly pony hooves (just checking to see if
27- anyone is reading this)
28- * Can be adapted to run over alternate transports like Bluetooth, or
29- anything else we can send framed messages over
30- * Less code (about 40% less in the iOS implementation)
31- * Cleaner implementation, with the generic messaging layer separated
32- from the replication-specific logic
33- * Protocol is inherently symmetric between client/server, which means
34- the two roles share a lot of common code
35- * Supports “conflict-free” servers, which require clients to resolve
36- conflicts before pushing changes.
37-
38- There is also a related https://blog.couchbase.com/data-replication-couchbase-mobile:[blog post] that is targeted towards end users.
39-
4016== Table of Contents
4117
4218toc::[]
@@ -49,41 +25,50 @@ Contents
49251. Architecture
5026~~~~~~~~~~~~~~~
5127
52- The new replication protocol is built on the multiplexed
28+ The replication protocol is built on the multiplexed
5329https://github.com/couchbaselabs/BLIP-Cocoa/blob/master/Docs/BLIP%20Protocol.md[BLIP
5430messaging protocol], which itself is layered on WebSockets. The relevant
5531aspects of the transport are:
5632
57- * Communication runs over a single socket.
58- * Both client and server can send *messages*. The protocol is
33+ * Communication runs over a single TCP socket.
34+ * Both client and server can send *messages* at any time . The protocol is
5935symmetrical.
6036* Message delivery is reliable and ordered.
61- * Messages are multiplexed -- any number can be in flight at once, and a
62- large message does not block the ones behind it.
37+ * Messages are multiplexed -- messages over a certain length are split into frames.
38+ Any number of messages can be in flight at once, and a large message does not block the ones behind it.
6339* A message is similar to an HTTP request in that it contains an
6440unlimited-size binary body plus a set of key/value properties.
6541* An unsolicited message is called a *request*.
6642* A request can be responded to (unless marked as no-reply) and the
6743*response* message can contain either properties and a body, or an
6844error.
6945
70- Other transport protocols could be used under the hood in some
71- circumstances, for example Bluetooth, as long as the message semantics
72- are preserved.
46+ BLIP is capable of running over other transport protocols, for example Bluetooth,
47+ as long as they support ordered delivery of framed binary messages.
7348
7449[[connecting]]
75- 2. Connecting
76- ~~~~~~~~~~~~~
50+ 2. Connecting and Versioning
51+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7752
7853The client opens a WebSocket connection to the server at path
7954`/`__dbname__`/_blipsync` (where _dbname_ is the name of the database.)
80- This begins as an HTTP GET request, and goes through authentication as
55+ This begins as an HTTP UPGRADE request, and goes through authentication as
8156usual, then upgrades to WebSocket protocol.
8257
8358The WebSocket sub-protocol name `BLIP_3+CBMobile_3`, sent in the
8459`Sec-WebSocket-Protocol` header, is used to ensure that both client and
8560server understand BLIP and the replicator protocol.
8661
62+ * `BLIP_3` refers to the version of the BLIP messaging protocol.
63+ This has been quite stable over time.
64+ * `CBMobile_3` refers to the major version of the replication protocol.
65+ This increments when there are incompatible changes to the protocol,
66+ and generally matches the major version of Couchbase Mobile itself.
67+ * Smaller changes in the replication protocol are handled by adding
68+ message properties or defining new messages. These are called out
69+ individually; for instance, the changes to support scopes & collections
70+ are marked with "[3.1+]".
71+
8772[[message-types]]
88733. Message Types
8974~~~~~~~~~~~~~~~~
@@ -97,6 +82,8 @@ Any response properties and/or body data are listed too. However, many
9782messages don't require any data in the response, just a success/failure
9883indication.
9984
85+ Message bodies are JSON by default.
86+
10087Most of these messages are sent by both client and server. Their usage
10188in the replication algorithm is described in the *Algorithm* section
10289below.
0 commit comments