Database / CouchDB Interview Questions
What is Couchbase Sync Gateway and how does it relate to CouchDB's replication model?
Couchbase Sync Gateway is the replication middleware layer in the Couchbase mobile stack. It sits between mobile clients running Couchbase Lite (the embedded mobile database) and a Couchbase Server cluster, handling authentication, authorization, and document routing. Historically it implemented a subset of the CouchDB replication protocol so that CouchDB-compatible clients could sync against it, but Couchbase has since moved toward its own DCP-based (Database Change Protocol) sync approach in newer versions.
The relationship to CouchDB's replication model:
- Early versions of Couchbase Sync Gateway exposed a CouchDB-compatible REST API and replication endpoint. This meant PouchDB could sync to Sync Gateway using exactly the same protocol it uses with CouchDB.
- Sync Gateway adds access control channels — each document is tagged with channels and each user is granted access to specific channels. This is a layer that CouchDB itself does not provide natively (CouchDB's access control is at the database level, not document level).
- From Couchbase Mobile 3.x onward, Couchbase Lite uses a proprietary BLIP WebSocket protocol (not the CouchDB HTTP replication protocol) for sync, diverging from CouchDB compatibility.
For CouchDB users, Sync Gateway is mainly relevant as a comparison point: if you need per-document access control with mobile sync, Sync Gateway's channel model is a more mature solution than CouchDB's validate_doc_update-based approach. Pure CouchDB users achieve similar results by combining PouchDB sync with per-user databases or filtered replication.
More Related questions...