{"id":2384,"date":"2016-09-11T06:43:09","date_gmt":"2016-09-11T06:43:09","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2384"},"modified":"2023-07-24T01:08:46","modified_gmt":"2023-07-24T08:08:46","slug":"sync-gateway-inter-instance-replication-code-sample","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/","title":{"rendered":"Sync Gateway Inter-instance Code Sample"},"content":{"rendered":"<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">In this\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/www.couchbase.com\/blog\/new-couchbase-mobile-v1.3-inter-instance-replication-sync-gateway\/\">post<\/a>, I went into some detail about replications between\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/get-started\/sync-gateway-overview\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Sync Gateway<\/a>\u00a0(SG) instances in\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/www.couchbase.com\/developers\/mobile\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Couchbase Mobile<\/a>\u00a0(CBM). I wrote a simple Java application with a Swing-based UI to illustrate a working example. I run the app along with two instances of SG to demonstrate everything.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">This diagram shows the flow in the application and the communications with the SG pair.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\"><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/september\/sync-gateway-inter-instance-replication-code-sample\/sg-replicate.png\" alt=\"Data flow diagram\" align=\"middle\" \/><\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">An editing pane allows us to enter JSON data. That data gets saved to the\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/www.couchbase.com\/developers\/mobile\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Couchbase Lite<\/a>\u00a0(CBL) local storage. We have two replications set up. One pushes data from the CBL database to the Sync Gateway instance I called the primary instance. I\u2019ll refer to it simply as Primary. Primary replicates itself to the backup SG instance (hereafter called Backup).<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">To see this happen, I monitor the\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/develop\/references\/sync-gateway\/rest-api\/index.html#operation---db--_changes-get?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">_changes feed<\/a>\u00a0from both Primary and Backup.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Everything runs together on my Mac. You can set up a complete CBM stack all running on your development machine. This makes initial development easier. It also helps understand how all the pieces fit together and work. I\u2019ll blog about this more in the future.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Let\u2019s walk through the configurations and the code.<\/p>\n<h2 id=\"configuring-sync-gateway\" style=\"color: #000000;font-family: sans-serif;line-height: 25.6px;text-align: start\">Configuring Sync Gateway<\/h2>\n<h4 id=\"backup\" style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Backup<\/h4>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I run each SG instance with its own JSON configuration file. The configuration for Backup is a little simpler. Here it is.<\/p>\n<pre style=\"overflow: auto;font-size: medium;color: #000000;line-height: 25.6px;text-align: start\"><code class=\"language-JSON hljs\" style=\"padding: 0.5em;color: #444444;background: #f0f0f0\">{\r\n  \"<span class=\"hljs-attr\">interface<\/span>\":<span class=\"hljs-string\" style=\"color: #880000\">\":5984\"<\/span>,\r\n  \"<span class=\"hljs-attr\">adminInterface<\/span>\":<span class=\"hljs-string\" style=\"color: #880000\">\":5985\"<\/span>,\r\n\r\n  \"<span class=\"hljs-attr\">log<\/span>\": [<span class=\"hljs-string\" style=\"color: #880000\">\"*\"<\/span>],\r\n  \"<span class=\"hljs-attr\">databases<\/span>\": {\r\n    \"<span class=\"hljs-attr\">db<\/span>\": {\r\n      \"<span class=\"hljs-attr\">server<\/span>\": <span class=\"hljs-string\" style=\"color: #880000\">\"walrus:\"<\/span>,\r\n      \"<span class=\"hljs-attr\">users<\/span>\": { \"<span class=\"hljs-attr\">GUEST<\/span>\": {\"<span class=\"hljs-attr\">disabled<\/span>\": <span class=\"hljs-literal\" style=\"color: #1f811f\">false<\/span>, \"<span class=\"hljs-attr\">admin_channels<\/span>\": [<span class=\"hljs-string\" style=\"color: #880000\">\"*\"<\/span>] } }\r\n    }\r\n  }\r\n}\r\n<\/code><\/pre>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Since we run two copies of SG, we have to make sure they use different network ports. By default, SG uses ports 4984 and 4985. The first couple of lines for Backup set it to listen on ports 5984 and 5985 instead. There\u2019s nothing special about those ports. Just make sure to pick ones that aren\u2019t used by other apps on your machine.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The rest of the config file causes SG to log everything, sets up to serve data from a special-purpose in-memory database (indicated by the keyword \u201cwalrus\u201d), and allows open access to anyone via the \u201cGUEST\u201d user. This is a nice piece to remember for early development. Walrus lets you use SG standalone, without a server backend. Using GUEST with all access means you can get things running without worrying about authentication and channel set up. Note by default SG logs to stderr. You can add an option to have it log to a file instead.<\/p>\n<h4 id=\"primary-and-inter-instance-replication\" style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Primary and Inter-instance Replication<\/h4>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">We set up the push replication in the config for Primary. It has some of the same boilerplate parameters.<\/p>\n<pre style=\"overflow: auto;font-size: medium;color: #000000;line-height: 25.6px;text-align: start\"><code class=\"language-JSON hljs\" style=\"padding: 0.5em;color: #444444;background: #f0f0f0\">{\r\n  \"<span class=\"hljs-attr\">log<\/span>\": [<span class=\"hljs-string\" style=\"color: #880000\">\"*\"<\/span>],\r\n  \"<span class=\"hljs-attr\">databases<\/span>\": {\r\n    \"<span class=\"hljs-attr\">db<\/span>\": {\r\n      \"<span class=\"hljs-attr\">server<\/span>\": <span class=\"hljs-string\" style=\"color: #880000\">\"walrus:\"<\/span>,\r\n      \"<span class=\"hljs-attr\">users<\/span>\": { \"<span class=\"hljs-attr\">GUEST<\/span>\": {\"<span class=\"hljs-attr\">disabled<\/span>\": <span class=\"hljs-literal\" style=\"color: #1f811f\">false<\/span>, \"<span class=\"hljs-attr\">admin_channels<\/span>\": [<span class=\"hljs-string\" style=\"color: #880000\">\"*\"<\/span>] } }\r\n    }\r\n  },\r\n\r\n  \"<span class=\"hljs-attr\">replications<\/span>\":[\r\n    {\r\n      \"<span class=\"hljs-attr\">source<\/span>\": <span class=\"hljs-string\" style=\"color: #880000\">\"db\"<\/span>,\r\n      \"<span class=\"hljs-attr\">target<\/span>\": <span class=\"hljs-string\" style=\"color: #880000\">\"https:\/\/localhost:5985\/db\"<\/span>,\r\n      \"<span class=\"hljs-attr\">continuous<\/span>\": <span class=\"hljs-literal\" style=\"color: #1f811f\">true<\/span>\r\n    }\r\n  ]\r\n}\r\n<\/code><\/pre>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The \u201creplications\u201d section is where the interesting stuff happens. Notice the entry is an array. You can specify any number of replications. Here we just have one.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">To specify a replication, you need to provide a source and a target. Recall all replications are one-way.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The \u201csource\u201d parameter indicates we want to replicate the database identified as \u201cdb\u201d. You can see the section under \u201cdatabases\u201d where we set this up with Walrus.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The target can be another database hooked to the same SG instance, or you can specify an HTTP URL like we did here. Use the name of the remote database for the path portion of the URL (\/db in this case).<\/p>\n<h4 id=\"running-sync-gateway\" style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Running Sync Gateway<\/h4>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I saved the configurations in two files, primary_gateway_config.json and backup_gateway_config.json. You can run SG manually from a command line. You can find information about downloading and running SG for different platforms\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/installation\/sync-gateway\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">here<\/a>.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I start Backup first. Otherwise Primary puts out a lot of messages about failures connecting to perform the replication.<\/p>\n<h2 id=\"the-java-app\" style=\"color: #000000;font-family: sans-serif;line-height: 25.6px;text-align: start\">The Java App<\/h2>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I wrote the Java app using Swing for the UI, using IntelliJ\u00a0IDEA for layout. Here\u2019s what the app looks like on startup.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\"><img decoding=\"async\" style=\"max-width: 800px\" src=\"\/wp-content\/original-assets\/2016\/september\/sync-gateway-inter-instance-replication-code-sample\/dbexplorer-0.png\" alt=\"DBExplorer on startup\" align=\"middle\" \/><\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">To use it, paste JSON into the leftmost text pane. Click the Save button. That stores a new JSON document in the CBL database. Syncing is off to begin. Click the Start button to enable it.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The middle text pane monitors the Primary changes feed. The rightmost pane monitors the Backup changes feed.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">With sync enabled, every time you save a document you should see both changes feeds respond. Here\u2019s what that looks like.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\"><img decoding=\"async\" style=\"max-width: 800px\" src=\"\/wp-content\/original-assets\/2016\/september\/sync-gateway-inter-instance-replication-code-sample\/dbexplorer-1.png\" alt=\"DBExplorer after saving a document\" align=\"middle\" \/><\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">You can find the source for the project on\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/github.com\/HodGreeley\/couchbase-lite-java-sg-replicate\">GitHub<\/a>. (Please note this sample highlights basics.\u00a0It is not production quality code.) Let\u2019s examine a few key pieces.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">There are four classes. Most of the UI is in DBExplorer.java. DBService.java is a fairly typical helper class. Take a look there to see how replications are set up between CBL and SG. Runtime.java exists mostly to have a shared instance of a\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/github.com\/FasterXML\/jackson\">Jackson<\/a>\u00a0JSON ObjectMapper.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">SGMonitor.java takes care of monitoring the two changes feeds. I use the\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/square.github.io\/okhttp\/\">OkHttp<\/a>\u00a0client library from Square to make the REST calls.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">To monitor the changes feed, I use what\u2019s known as longpolling. With longpoll, if there\u2019s no new data to transfer, the HTTP call doesn\u2019t return immediately. Instead it waits until new data gets sent (or it times out). The connection is then closed. This means you need a loop to keep checking for change records. Note the changes records are sent as JSON. The results get bundled as an array, so you can have more than one record per response.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">To simplify creating the HTTP request, I create a URL builder with the parameters needed for every call added.<\/p>\n<pre style=\"overflow: auto;font-size: medium;color: #000000;line-height: 25.6px;text-align: start\"><code class=\"language-Java hljs\" style=\"padding: 0.5em;color: #444444;background: #f0f0f0\">urlBuilder = HttpUrl.parse(url).newBuilder()\r\n        .addPathSegment(<span class=\"hljs-string\" style=\"color: #880000\">\"_changes\"<\/span>)\r\n        .addQueryParameter(<span class=\"hljs-string\" style=\"color: #880000\">\"feed\"<\/span>, <span class=\"hljs-string\" style=\"color: #880000\">\"longpoll\"<\/span>)\r\n        .addQueryParameter(<span class=\"hljs-string\" style=\"color: #880000\">\"timeout\"<\/span>, <span class=\"hljs-string\" style=\"color: #880000\">\"0\"<\/span>);\r\n<\/code><\/pre>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Reading this out, we\u2019re connecting to the _changes endpoint, using a feed type of longpoll, and setting the timeout to 0 (0 means never time out).<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I set up a SwingWorker thread to run the loop. It builds an HTTP request, fires it off, and waits for the response.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">The final trick here is in telling Sync Gateway what data you need. Every SG _changes response contains a \u201clast_seq\u201d property. This property is just an integer that helps track which records a client has already received. It is the responsibility of the client to keep track of the data it has processed. Once you\u2019ve handled a response, you need to add or update the \u201csince\u201d parameter to future requests. SG then knows to pass only newer changes.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Here\u2019s the latter part of the loop.<\/p>\n<pre style=\"overflow: auto;font-size: medium;color: #000000;line-height: 25.6px;text-align: start\"><code class=\"language-Java hljs\" style=\"padding: 0.5em;color: #444444;background: #f0f0f0\">String body = response.body().string();\r\n\r\nJsonNode tree = mapper.readTree(body);\r\n\r\nurlBuilder.setQueryParameter(<span class=\"hljs-string\" style=\"color: #880000\">\"since\"<\/span>, tree.get(<span class=\"hljs-string\" style=\"color: #880000\">\"last_seq\"<\/span>).asText());\r\n\r\npublish(body);\r\n<\/code><\/pre>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">I use the Jackson ObjectMapper to parse the change record. I then add \u201csince\u201d as a query parameter with the value extracted from the last_seq property. That sets up the URL for the next request. The publish call takes care of updating the text area in the UI.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">That&#8217;s it. \u00a0The entire project can be run on one machine. \u00a0This will let you explore Couchbase Lite, Sync Gateway, and replications in detail. \u00a0Enjoy.<\/p>\n<h2 id=\"postscript\" style=\"color: #000000;font-family: sans-serif;line-height: 25.6px;text-align: start\">Postscript<\/h2>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">Check out more resources on our\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/www.couchbase.com\/developers\/community\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">developer portal<\/a>\u00a0and follow us on Twitter\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/twitter.com\/CouchbaseDev\">@CouchbaseDev<\/a>.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">You can post questions on our\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/www.couchbase.com\/forums\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">forums<\/a>. And we actively participate on\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/stackoverflow.com\/questions\/tagged\/couchbase\">Stack Overflow<\/a>.<\/p>\n<p style=\"color: #000000;font-family: sans-serif;font-size: medium;line-height: 25.6px;text-align: start\">You can follow me personally at\u00a0<a style=\"color: #265778;text-decoration: none\" href=\"https:\/\/twitter.com\/HodGreeley\">@HodGreeley<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this\u00a0post, I went into some detail about replications between\u00a0Sync Gateway\u00a0(SG) instances in\u00a0Couchbase Mobile\u00a0(CBM). I wrote a simple Java application with a Swing-based UI to illustrate a working example. I run the app along with two instances of SG to [&hellip;]<\/p>\n","protected":false},"author":73,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1810],"tags":[1562],"ppma_author":[9042],"class_list":["post-2384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-mobile","tag-replication"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Sync Gateway Inter-instance Code Sample - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sync Gateway Inter-instance Code Sample\" \/>\n<meta property=\"og:description\" content=\"In this\u00a0post, I went into some detail about replications between\u00a0Sync Gateway\u00a0(SG) instances in\u00a0Couchbase Mobile\u00a0(CBM). I wrote a simple Java application with a Swing-based UI to illustrate a working example. I run the app along with two instances of SG to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-11T06:43:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-24T08:08:46+00:00\" \/>\n<meta name=\"author\" content=\"Hod Greeley, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@HodGreeley\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hod Greeley, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\"},\"author\":{\"name\":\"Hod Greeley, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4\"},\"headline\":\"Sync Gateway Inter-instance Code Sample\",\"datePublished\":\"2016-09-11T06:43:09+00:00\",\"dateModified\":\"2023-07-24T08:08:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\"},\"wordCount\":1128,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"replication\"],\"articleSection\":[\"Couchbase Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\",\"name\":\"Sync Gateway Inter-instance Code Sample - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2016-09-11T06:43:09+00:00\",\"dateModified\":\"2023-07-24T08:08:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sync Gateway Inter-instance Code Sample\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4\",\"name\":\"Hod Greeley, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/21eb69cb5d4a401fb23b149e4f4e9e87\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g\",\"caption\":\"Hod Greeley, Developer Advocate, Couchbase\"},\"description\":\"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.\",\"sameAs\":[\"https:\/\/hod.greeley.org\/blog\",\"https:\/\/x.com\/HodGreeley\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/hod-greeley\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Sync Gateway Inter-instance Code Sample - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/","og_locale":"en_US","og_type":"article","og_title":"Sync Gateway Inter-instance Code Sample","og_description":"In this\u00a0post, I went into some detail about replications between\u00a0Sync Gateway\u00a0(SG) instances in\u00a0Couchbase Mobile\u00a0(CBM). I wrote a simple Java application with a Swing-based UI to illustrate a working example. I run the app along with two instances of SG to [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/","og_site_name":"The Couchbase Blog","article_published_time":"2016-09-11T06:43:09+00:00","article_modified_time":"2023-07-24T08:08:46+00:00","author":"Hod Greeley, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@HodGreeley","twitter_misc":{"Written by":"Hod Greeley, Developer Advocate, Couchbase","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/"},"author":{"name":"Hod Greeley, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4"},"headline":"Sync Gateway Inter-instance Code Sample","datePublished":"2016-09-11T06:43:09+00:00","dateModified":"2023-07-24T08:08:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/"},"wordCount":1128,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["replication"],"articleSection":["Couchbase Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/","url":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/","name":"Sync Gateway Inter-instance Code Sample - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2016-09-11T06:43:09+00:00","dateModified":"2023-07-24T08:08:46+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/sync-gateway-inter-instance-replication-code-sample\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Sync Gateway Inter-instance Code Sample"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4","name":"Hod Greeley, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/21eb69cb5d4a401fb23b149e4f4e9e87","url":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","caption":"Hod Greeley, Developer Advocate, Couchbase"},"description":"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.","sameAs":["https:\/\/hod.greeley.org\/blog","https:\/\/x.com\/HodGreeley"],"url":"https:\/\/www.couchbase.com\/blog\/author\/hod-greeley\/"}]}},"authors":[{"term_id":9042,"user_id":73,"is_guest":0,"slug":"hod-greeley","display_name":"Hod Greeley, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","author_category":"","last_name":"Greeley","first_name":"Hod","job_title":"","user_url":"https:\/\/hod.greeley.org\/blog","description":"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2384"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2384\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2384"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}